Live data from Hacker News

Fetch API has landed into Node.js

github.com

41–50 of 210 posts

Re: Fetch API has landed into Node.js

#41
post #21

Earlier quoted context omitted.

I'm happy to hear that but I had a very small part in it all! The person who took it through the finish line (and deserves the most props here IMO) is Michael https://github.com/targos The people who worked most on Undici are Matteo https://github.com/mcollina and Robert https://github.com/ronag The person to work most on fetch in Undici is Ethan https://github.com/Ethan-Arrowood Also worth calling our James whose wo…

What does undici mean?

eleven

Re: Fetch API has landed into Node.js

#42
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.

This is awesome, thank you. Excited to take it for a spin.

Re: Fetch API has landed into Node.js

#43
post #21

Earlier quoted context omitted.

I'm happy to hear that but I had a very small part in it all! The person who took it through the finish line (and deserves the most props here IMO) is Michael https://github.com/targos The people who worked most on Undici are Matteo https://github.com/mcollina and Robert https://github.com/ronag The person to work most on fetch in Undici is Ethan https://github.com/Ethan-Arrowood Also worth calling our James whose wo…

What does undici mean?

https://undici.nodejs.org/ "Undici means eleven in Italian. 1.1 -> 11 -> Eleven -> Undici. It is also a Stranger Things reference."

Re: Fetch API has landed into Node.js

#45
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 res.status 0 and no headers, as per spec. You aren't allowed to see the content of a redirect, like in a browser.

[0] https://github.com/nodejs/undici/issues/1072 [1] https://github.com/denoland/deno/pull/8353 [2] https://github.com/denoland/deno/issues/4389

Re: Fetch API has landed into Node.js

#47
post #21

Earlier quoted context omitted.

I'm happy to hear that but I had a very small part in it all! The person who took it through the finish line (and deserves the most props here IMO) is Michael https://github.com/targos The people who worked most on Undici are Matteo https://github.com/mcollina and Robert https://github.com/ronag The person to work most on fetch in Undici is Ethan https://github.com/Ethan-Arrowood Also worth calling our James whose wo…

What does undici mean?

"undici" means "eleven" in italian. But I don't know the rationale behind the name

Re: Fetch API has landed into Node.js

#48
post #31
post #24

Earlier quoted context omitted.

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…

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.

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

#49
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.

Yes I could imagine and I have experience of developing apis with "bugs" that you kind of need to keep since people come to depend on it working a certain way.

But I can't help to feel like Node is progressing kind of slow compared to other languages / tools. This is just a personal impression from a bystander who is not really into the actual progression though. I have a feeling that node used to push new features all the time but in last couple of years have stagnated somewhat. Stuff like imports etc is still not really here.

I understand that developing an api that has such huge userbase as node is a massive undertaking that probably has issues that I can't imagine but it doesn't really help me in my day-to-day experience with it.

Re: Fetch API has landed into Node.js

#50
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…

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 requests out of the box comparable to high level HTTP clients like superagent, axios etc. that have been in use for the last decade, since before fetch was conceived, with whatever benefits fetch provides (I think it's cancellable now?).

Post reply on HN