Got: Comparison with node-fetch

Created on 24 Oct 2018  Â·  7Comments  Â·  Source: sindresorhus/got

I think there are some inaccuracies:

  • Stream API: node-fetch has res.body.pipe.
  • Custom defaults: node-fetch does merge Headers and Request options correctly per spec.

Not butthurt of anything, just bump into this table and think the comparison can be improved.

documentation question

Most helpful comment

@szmarczak love to get .getReader() working in some way. We were expecting whatwg stream to be a part of nodejs core but the PR didn't land. (see https://github.com/nodejs/node/pull/22352), so using a polyfill might be the only solution for now.

All 7 comments

Stream API: node-fetch has res.body.pipe.

That's just the built-in Node.js http.request response body stream, right? Which is not that useful for most cases, as you'll lose the benefit of node-fetch, compatibility with Fetch. Got has a dedicated .stream() method that returns a stream that also proxies headers and other things. For node-fetch, the equivalent would be https://github.com/bitinn/node-fetch/issues/387.

Custom defaults: node-fetch does merge Headers and Request options correctly per spec.

That's just a small part of it. The other libs that support 'custom defaults' supports it for all options.

@sindresorhus I see your take, But:

  • we didn't switch to web stream because node-fetch are for nodejs and at the time getReader wasn't available. res.body.pipe isn't a standard API in Fetch spec but .pipe is exactly what people are looking for on nodejs. Note that we also support the standard .clone API which operates on stream.
  • I just think it's unfair to categorize got as having stream api while node-fetch is categorized as doesn't simply because of spec compliance issue.
  • As for the custom defaults, sure, if your argument is "only merging the main instance" counts.

res.body.pipe isn't a standard API in Fetch spec but .pipe is exactly what people are looking for on nodejs.

But people use node-fetch to have a familiar API or most often identical API on the server-side as in the browser and this breaks that promise.

I just think it's unfair to categorize got as having stream api while node-fetch is categorized as doesn't simply because of spec compliance issue.

It would also be unfair to got and request if it was categorized as such though.

  • node-fetch is isomorphic, but only supports a "stream" API for Node.js.
  • The stream API is not a first-class citizen. It's just exposing the Node.js response stream. It doesn't have nice conveniences like forwarding headers, redirect handling, etc.

We can add a ✖ [1] and add a note that node-fetch somewhat supports streams.

node-fetch is isomorphic, but only supports a "stream" API for Node.js.

The stream API is not a first-class citizen. It's just exposing the Node.js response stream. It doesn't have nice conveniences like forwarding headers, redirect handling, etc.

PS: I know all these are just technicality and we both have better things to do than correcting a comparison table, so consider this a suggestion for change not a request :)

Let's summarize: node-fetch aims to be compatible with the fetch, we should not expect any additional features. So if there are any, they're node-specific. No need to argue about node-specific things (proxying headers etc.).

I don't mind ticking node-fetch. But I think we should leave a note that it's a bit different than the window.fetch.

@bitinn It'd be very nice to have .getReader() :)

@sindresorhus thoughts?

@szmarczak love to get .getReader() working in some way. We were expecting whatwg stream to be a part of nodejs core but the PR didn't land. (see https://github.com/nodejs/node/pull/22352), so using a polyfill might be the only solution for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukehorvat picture lukehorvat  Â·  3Comments

joolfe picture joolfe  Â·  3Comments

erfanium picture erfanium  Â·  3Comments

dAnjou picture dAnjou  Â·  3Comments

lukechu10 picture lukechu10  Â·  3Comments