make-fetch
Implement your own fetch()
with node.js streams
Usage
npm i --save make-fetch
const makeFetch = require('make-fetch')
const fetch = makeFetch(async (request) => {
const {
url,
headers,
referrer,
method,
body,
signal
} = request
return {
statusCode: 200,
headers: {
"something": "whatever"
},
data: asyncIterator
}
})
const response = await fetch('myscheme://whatever/foobar')
console.log(await response.text())
Gotchas
- The
response.body
is an Async Iterable of Buffer objects rather than a WHATWG ReadableStream - Eventually ReadableStream will become async iterable so you'll be able to iterate either normally