This is still experimental and we'd love to hear from the community what you'd like to see.
This is still experimental and we'd love to hear from the community what you'd like to see.
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
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?).
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.
The rest of your "improvements" aren't that. They're opinions, opinions laser focused on a JSON centric api.
I'm sorry to say this, but not all of the web is one big JSON blob.
Some of us have to talk to SOAP (xml) services.
Sometimes it's weird rpc stuff with protobuf.
Or even just pulling down raw binary data and feeding that through an API/library that wasn't built for web streams.
Honestly, the amount of code you need to add over the top of a primitive like the Fetch API to get what you wanted (bar the redirect change) is trivial and minimal.
I don’t know if chrome apps are still in existence, but if they are the “server side” fetch spec could apply to them too.
All the existing HTTP clients discussed in the previous post also run in the browser.
In case you disagree, you may want to reply why instead of down voting.
Edit: also, you are being downvoted because the etiquette on HN are that you don't ask "why was X downvoted".
We could have stuck with ‘if index is not equal to minus one’ but we have array includes now for the same reason.
> set JSON as the default request content type
or something similarly subjective.
Downvoting is going a bit too far, but bundling a few individual opinions on defaults alongside broadly accepted (implemented in both Node & Deno after much discussion) features seems... presumptuous.
> ...we'd love to hear from the community what you'd like to see.
In our tests, fetch on Deno was wayy faster than undici fetch that now has been merged into nodejs.
I couldn't figure out why that was case, but forwarding requests over node's http2 client (instead of undici fetch) then had comparable (but not as fast) performance as Deno (presumably because our hand rolled impl lacked connection pooling).
I am confident that Node's implementation will _eventually_ have comparable performance.
That said: please do open an issue in the undici repo at https://nodejs.org/node/undici so this gets tracked.
The question is totally legitimate but please assume core doesn't make "load random binary" level kind of goofs :)
Its unverified binaries are just as good as random binaries, and silently replacing any pre-existing yarn/pnpm/whathaveyou without checking if it was perhaps a custom build is not exactly predictable either.
Other than Corepack, though, I think you people are doing an amazing job!
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 work on web streams in Node as well as events/cancellation helped drive a bunch of this.
I can name maybe 50 people who worked on this effort overall at some capacity (I am one of them - spending maybe 40 years on APIs to help enable this).
Note the job isn't entirely done and help is very much appreciated!
I hope you realize no disrespect, this will greatly improve the daily work for me since I use node at work every day.
> 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 answered that below (check it out) but note how expensive adding a bad API is vs. asking people for one more `npm install` :) There is more discussion in https://github.com/nodejs/node/issues/19393 and in https://docs.google.com/document/d/1tn_-0S_FG_sla81wFohi8Sc8... a discussion from 2018 we had on it
Last question I have is will this be included in the next version of the LTS version or how do experimental features usually progress for someone who are unfamiliar?
Can't wait until I can use fetch in my codebase without any additional dependencies!
They could have built a fetch interface on top of http, but they probably saw an opportunity to make more drastic improvements.
Node uses undici JS library. Undici includes a C HTTP parser that is used via webassembly. The parser is generated from rules that are implemented in JS/TS using llparse framework.
A native C binary there in the middle is quite surprising.
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.
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.
Node also isn’t actually a language, so there’s a lot of stuff that Node developers get in new version, but it’s actually being done in the V8 project.
And this is no obscure corner case, ts-node is huge
Here is discussion about it in Node with some (pretty old) discussion https://docs.google.com/document/d/1tn_-0S_FG_sla81wFohi8Sc8...
I thought it was a Node popular library.
It's promise based (thus easier to integrate into code than older callback styles), and designed to give some better options around CORS and handling responses.
> Why it should be in node?
There is a push to adopt some certain "web apis" (APIs that emerged in web browsers) to increase compatibility, reusability and reduce cognitive load when working with both backend and frontend javascript.
Having a common low level call like fetch() means that libraries that are built atop it (SDKs to talk to services, or apply common middleware like JSON:API, oAuth etc) can be shared between node/deno and browsers.
It's still very common to see Node modules that use require(), for example, but would otherwise work flawlessly in a browser where there is no require() support (without using shims and other libraries).
Node has supported ESModules (`import`) for a while and you can use it (either by naming your files `.mjs` or setting `type: module` in your package.json.
There is a solid interop story between require/import and you can mix if you want.
`require` is going to be supported "forever" so code doesn't break and both module systems work.
As for the general question: Node is committed to supporting modern JavaScript and to not allow such a gap to be created. If you see a place Node doesn't do a great job at that please tell us!
For example to use `require` inside ESModules you would do:
```mjs import { createRequire } from 'module'; const require = createRequire(import.meta.url); require('./whatever-in-cjs'); ```
There is a reason this isn't "by default" though since ESM doesn't "silently" interop with CJS to not make writing universal code harder.
https://github.com/arcanis/clipanion/blob/master/rollup.conf...
"Seemingly increasing gap" - how did you come to that conclusion? If anything the gap has reduced since the availability of ES modules. I see more and more libraries preferring ES modules, but ultimately that's up to the library developers.
Curious to check but quick question: does it support upload progress? If not, is it considered?
If you upload a string for example you would have to take an extra step to get upload progress (make it into a stream and monitor that).
There is additional (unrelated) talk in the fetch standard itself to provide this sort of functionality as part of `fetch` which would save the middle step.
This was a huge pain for us. We develop an SDK that needs to work on Node, browsers and React Native.
I am super happy to hear about this :)