News for hackers. Stuff that matters.
Re:Fetch API has landed into Node.js by mcraiha on Tuesday February 01, 2022 @08:29AM (#30162068)
Why it took so long? e.g. Deno had fetch support for ages
Re:Fetch API has landed into Node.js by inglor on Tuesday February 01, 2022 @08:41AM (#30162211)
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'ish web APIs.

As a side note just to show positive collaboration: that work made me make maybe 10 PRs fixing things in EventTarget in Deno - and Deno helped Node a bunch now when landing fetch.

Then web streams and blobs and a few other things as well as the undici work in the background.

Then undici-fetch by Ethan, merge into Undici and then the PR by Michael - and it's still not done :)

Finally

Re:Fetch API has landed into Node.js by dstroot on Tuesday February 01, 2022 @08:52AM (#30162332)
First, this is awesome and congratulations! Second this sounds like a lot of work! Can you comment why was it so hard to add fetch to node, yet packages like “node-fetch” have existed for some time and seem to implement fetch rather easily? Only asking from a curiosity perspective.
Re:Fetch API has landed into Node.js by inglor on Tuesday February 01, 2022 @09:08AM (#30162563)
node-fetch (which is great btw!) implements fetch "reasonably" as in stuff like `fetch('./foo').then(x => x.json())` works but it's very far from a "real" fetch.

Some people argued users would still like it and there was an attempt[1] by Myles but at the end of the day - the changes were pretty big.

For example: a response body in fetch is a web stream (a whole new stream type) and to cancel you use an AbortController (web type) which is an EventTarget (another web type). `node-fetch` uses Node streams instead which is very reasonable but not something a platform can "get away" with while still calling it fetch.

Here is a comment I wrote about it in the tracker during the PR review process https://github.com/nodejs/node/pull/41749#issuecomment-10257...

[1](https://github.com/nodejs/node/pull/27979)

Re:Fetch API has landed into Node.js by dstroot on Tuesday February 01, 2022 @12:11PM (#30165701)
THANKS!
Re:Fetch API has landed into Node.js by msoad on Tuesday February 01, 2022 @09:22AM (#30162752)
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 by flakiness on Tuesday February 01, 2022 @06:04PM (#30170909)
I came here to ask the same question. Thanks for this thoughtful comment and congrats!
Re:Fetch API has landed into Node.js by cphoover on Tuesday February 01, 2022 @08:42AM (#30162221)
Fetch evolved after promises had been standarized as the way of doing async, whereas node is older than that. Node originally used callback style for its core API and had another method for making http requests. Since fetch, developed in the browser, OS contributors have filled the void of a promise supporting http requesr library, with packages like axios, and isomorphic-fetch. Only now that the standards have finalized and we have reached consistent browser support has core team has made it a priority to include it in core.
Re:Fetch API has landed into Node.js by Mikeb85 on Tuesday February 01, 2022 @10:27AM (#30163769)
Because Node is legacy and Ryan Dahl moved on to Deno... Node is just an outdated 'standard' at this point.
Re:Fetch API has landed into Node.js by engineerthrwawy on Tuesday February 01, 2022 @11:01AM (#30164253)
I don't think that's an accurate characterization of the fork.
Re:Fetch API has landed into Node.js by Mikeb85 on Tuesday February 01, 2022 @11:12AM (#30164478)
Calling it a fork certainly isn't accurate...
Re:Fetch API has landed into Node.js by cphoover on Sunday February 06, 2022 @07:14PM (#30238536)
I think its more accurate than calling it an outdated standard.