News for hackers. Stuff that matters.
Re:Fetch API has landed into Node.js by nailer on Tuesday February 01, 2022 @09:16AM (#30162653)
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?).

Re:Fetch API has landed into Node.js by inglor on Tuesday February 01, 2022 @09:26AM (#30162796)
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.

Re:Fetch API has landed into Node.js by andrewl-hn on Tuesday February 01, 2022 @09:59AM (#30163297)
Does it have to be a buy-in, though? You could agree on server-specific extensions to fetch and codify them in the same spec (so it doesn't get lost otherwise). Browser vendors wouldn't need to implement it but they will still keep an eye on it when working on future browser apis.
Re:Fetch API has landed into Node.js by tehbeard on Tuesday February 01, 2022 @10:22AM (#30163670)
Codifying the redirect behaviour for server/"trusted" envs makes some sense with Deno/node doing the same thing. I'm not versed enough in the standards orginazation politics to say if that's viable though.

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.

Re:Fetch API has landed into Node.js by Scarbutt on Tuesday February 01, 2022 @10:58AM (#30164206)
Can you share your setup for talking to SOAP services?
Re:Fetch API has landed into Node.js by true_religion on Tuesday February 01, 2022 @10:43AM (#30164007)
It would be useful for trusted browser extensions too, as well as probably Electon apps as well.

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.

Re:Fetch API has landed into Node.js by nailer on Tuesday February 01, 2022 @10:59AM (#30164228)
> Browsers likely don't have a lot of incentive to make spec changes only Node is interested in

All the existing HTTP clients discussed in the previous post also run in the browser.

Re:Fetch API has landed into Node.js by the_duke on Tuesday February 01, 2022 @04:54PM (#30169994)
None of the things you mentioned are reasonable default behaviours, and are easy one liners. You don't need a library for any of that.
Re:Fetch API has landed into Node.js by nailer on Tuesday February 01, 2022 @05:22PM (#30170349)
Thanks for your opinion, however as mentioned, or as you’ll be aware if you’ve used JavaScript, these are well worn cow paths that have been default in the most popular HTTP clients for a decade now.
Re:Fetch API has landed into Node.js by vanviegen on Tuesday February 01, 2022 @09:34AM (#30162911)
Why is this being down voted? This comment seems to be making a reasonable case.

In case you disagree, you may want to reply why instead of down voting.

Re:Fetch API has landed into Node.js by simlevesque on Tuesday February 01, 2022 @09:44AM (#30163073)
Because fetch just landed in Node.js, making it a standard present in every context after like 5 years and he want to change the standard now.

Edit: also, you are being downvoted because the etiquette on HN are that you don't ask "why was X downvoted".

Re:Fetch API has landed into Node.js by nailer on Tuesday February 01, 2022 @11:03AM (#30164313)
As mentioned existing HTTP clients had this behaviour back in 2012, the designers of fetch chose to ignore these cowpaths in favour of a more minimal implementation requiring the use of third party HTTP clients in both browsers and node, simply to have reasonable defaults and not repeat oneself, for the foreseeable future.
Re:Fetch API has landed into Node.js by andreigheorghe on Tuesday February 01, 2022 @02:54PM (#30168243)
the value the js community gets from `fetch` being a unified standard is far, far greater than the benefit you as a developer would get from not having to add 15 extra LOC around `fetch`, that you'll probably hide behind a `fetchJSON` function anyway.
Re:Fetch API has landed into Node.js by nailer on Tuesday February 01, 2022 @05:25PM (#30170387)
Point is everyone had a slightly different 150 LOC or a library to achieve essentially the same thing.

We could have stuck with ‘if index is not equal to minus one’ but we have array includes now for the same reason.

Re:Fetch API has landed into Node.js by lucideer on Wednesday February 02, 2022 @09:34AM (#30178074)
I didn't downvote, but my guess is its primarily a kneejerk reaction to the following line:

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