Live data from Hacker News

Fetch API has landed into Node.js

github.com

51–60 of 210 posts

Re: Fetch API has landed into Node.js

#51
One thing I hate about fetch() is that you can't manually follow redirects. Using { redirect: 'manual' } doesn't expose the Location header of the redirect, so it's essentially useless. I know that node-fetch fixed this issue, so I hope the official Node fetch() does not have the same problem.

Re: Fetch API has landed into Node.js

#53
post #51

One thing I hate about fetch() is that you can't manually follow redirects. Using { redirect: 'manual' } doesn't expose the Location header of the redirect, so it's essentially useless. I know that node-fetch fixed this issue, so I hope the official Node fetch() does not have the same problem.

We are not, this is a place the server-side implementation is going to diverge and this was discussed in the PR: https://github.com/nodejs/node/pull/41749#issuecomment-10254...

Re: Fetch API has landed into Node.js

#54
post #34

Earlier quoted context omitted.

Quick question, judging from the commit alone this seems like a rather small change. I assume there's more to it though. I just wonder how come features like this that kind of seems obvious to include in the ecosystem takes quite some time to land? I understand the reality is more complex perhaps, so I am genuinely curious. I hope you realize no disrespect, this will greatly improve the daily work for me since I use…

my guess is that this adds stuff to the global object which has backwards compatibility concerns. And with every public API: Once you add it, you can't really hope to ever change it and even bug-fixes could be breaking some user's code (because they relied on the bug), so you have to be very careful to ship your public API as bug-free as possible.

Meh, the js/ts ecosystem breaks things all the time. At least 2 weeks ago you couldn’t run typescript with ts-node, unless you explicitly enabled highly experimental loader flags.

And this is no obscure corner case, ts-node is huge

Re: Fetch API has landed into Node.js

#55
post #24
post #15

Why it took so long? e.g. Deno had fetch support for ages

Basically because fetch isn't a great API for servers it took a while to get consensus on actually landing it for the interoprability/simple API value. Then it took a while to get consensus it's fine to do even if we can't implement the standard fully and diverge from it on stuff like CORS (like Deno does). Then there were a bunch of work adding APIs like `EventTarget` and `AbortSignal` to Node.js which are quirky'is…

Interesting! What CORS even means in server? Never thought about this. What's a server's origin to begin with?!

Re: Fetch API has landed into Node.js

#56
post #53
post #51

One thing I hate about fetch() is that you can't manually follow redirects. Using { redirect: 'manual' } doesn't expose the Location header of the redirect, so it's essentially useless. I know that node-fetch fixed this issue, so I hope the official Node fetch() does not have the same problem.

We are not, this is a place the server-side implementation is going to diverge and this was discussed in the PR: https://github.com/nodejs/node/pull/41749#issuecomment-10254...

This is really, really great to hear. Thanks for all the hard work!

Re: Fetch API has landed into Node.js

#57
post #4

Hey, Node core person here (and the person who triggered the land) - we're super excited for this and would love help and feedback. This is still experimental and we'd love to hear from the community what you'd like to see.

Is there any chance to break spec and allow manual redirect handling? the fetch API makes a lot of sense in a browser, but imo this is a pretty crucial feature that undici's implementation lacks. [0] Deno decided to break spec [1][2] so the following code works fine: fetch('https://httpbin.org/status/302', {redirect: 'manual'}) .then(res => console.log(res.status, res.headers)) In undici this will succeed but with re…

Yes, this is a place where Node.js will diverge from the spec see discussion on the fetch PR https://github.com/nodejs/node/pull/41749#issuecomment-10254...

Re: Fetch API has landed into Node.js

#58
post #50

Earlier quoted context omitted.

Is there any chance to break spec and allow manual redirect handling? the fetch API makes a lot of sense in a browser, but imo this is a pretty crucial feature that undici's implementation lacks. [0] Deno decided to break spec [1][2] so the following code works fine: fetch('https://httpbin.org/status/302', {redirect: 'manual'}) .then(res => console.log(res.status, res.headers)) In undici this will succeed but with re…

A better idea would be to replace / improve the fetch spec. Handle redirects, set JSON as the default request content type, encode URI components for users, decode response bodies with JSON headers as JS objects, etc. Right now most developers either write their own library to do these things on top of fetch or another HTTP client or use a third party library from npm. A new standard would allow us to make http reque…

A new standard would need buy-in from browsers to actually be a standard. Browsers likely don't have a lot of incentive to make spec changes only Node is interested in (like making the whole spec more complicated from their point of view because of Node's (or Deno's) different security model).

The level of collaboration and good-faith we've been getting from spec bodies like WHATWG is very high as it is and we really don't want to push or abuse it.

Post reply on HN