DEV Community

Discussion on: Poke: A Super Handy HTTP Request Library

Collapse
 
anshrk profile image
Anshrk • Edited

Looks cool, but how is it different from fetch or axios?

Collapse
 
lawson_cheng profile image
Lawson Cheng

The poke library also support listen to difference events,
and easy access to stream : )

E.g

// Using callback
poke(hostname , pokeOptions)
// listen to response retrived
.on('response', result => {
    console.log(result)
})
// on chunk is recieved
.on('data', (chunk) => {
    // handle your data here
    console.log(d)
})
// on request eneded
.on('end', () => {
    console.log('Request is finished')
})
// listening to error
.on('error', (result) => {
    // handle error
    console.log(result.error)
})
Enter fullscreen mode Exit fullscreen mode

e.g 2

// get image
poke('https://via.placeholder.com/100x100')
// write data as an image file
.pipe(fs.createWriteStream('image.png'))
Enter fullscreen mode Exit fullscreen mode