4 ms·
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
by inglor 5y ago
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
- dstroot 5y agoFirst, 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.
- inglor 5y agonode-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-1025720476 https://github.com/nodejs/node/pull/41749#issuecomment-10257... [1](https://github.com/nodejs/node/pull/27979 https://github.com/nodejs/node/pull/27979)
- dstroot 5y agoTHANKS!
- msoad 5y agoInteresting! What CORS even means in server? Never thought about this. What's a server's origin to begin with?!
- flakiness 5y agoI came here to ask the same question. Thanks for this thoughtful comment and congrats!