5 ms·
Ive used Fetch in the past, great lib. I'm curious why Node core has decided to make this an official part of Node? From one perspective there could be a hard
by sealthedeal 5y ago
Ive used Fetch in the past, great lib. I'm curious why Node core has decided to make this an official part of Node? From one perspective there could be a hard argument that this should never be a part of Node as it is an external library and not a building block of the language? Almost feels like feature creep for the core language? I know that's not the intent, but wanting to understand the logic behind this decision :)
- prollings 5y agoThey're talking about JavaScript's fetch API. It's not an external library.
- zamadatix 5y agoIt ships browsers but not because it's a JS standard (ECMA) rather a web standard (WHATWG). Almost everything in JS is an external library as it doesn't have a true stdlib to go with the language just a core language and implementation specific APIs like browser Fetch or Node sockets. Hopefully WebSockets (W3C/IETF) will get embedded in Node's core one day as well.
- wruza 5y agoI second this, since fetch is a wrapper around xhr (though doesn’t have to be because node is a non-restricted runtime), and it diverged already for redirect semantics. It’s news, but is it big?
- samtho 5y ago> It’s news, but is it big? As someone who has been working almost exclusively on Node.js applications for years now, this is big. Front-end developers have, for years, enjoyed this wrapper around the clunky XHR API. It is simple, intuitive, and it comes _free_ in the browser environment (and was easily shimmable before it was standard). Additionally, the depreciation of the popular request[0] a while ago, there has been a gap in The Right Way to do http requests without going into the low-level API that ‘http(s)’ provides. Fetch is promised-based (enabling seamless async/await) and, most importantly, standardized. Basically, fetch provides a meaningful abstraction atop each platforms’ implementation of http-request-doing further unifying server-side and client-side patterns and idioms. [0]: https://www.npmjs.com/package/request https://www.npmjs.com/package/request
- wruza 5y agonpm i request node-fetch make-fetch-happen axios. Just out of top of my head.
- ripley12 5y agoAs a person who only occasionally writes JS and has zero interest in keeping track of the differences between client-side and server-side JS - fetch has been a big friction point for me in the past, it's big news to me.
- pitaj 5y agoFetch is a standard browser API.
- wruza 5y agoAnd so are navigator, localStorage and classes under window, like EventTarget.
- themikesanto 5y agoYeah. What's your point?
- wruza 5y agoComments like “it’s standard” do not answer the original question: “I'm curious why Node core has decided to make this an official part of Node?” The standard describes many functions and classes. What makes fetch more land-able than e.g. the event system, of which node has incompatible implementation? Or feature detection via navigator. Why it? What were the main point(s) of adding fetch specifically?
- ravenstine 5y agoSure it does. If something is standard, and it makes sense in the context of a backend, then it's convenient to just use the same API on both ends. Navigator makes almost no sense on the backend unless maybe it worked as a dummy polyfill object.
- ramblerman 5y agofetch is part of the client side standard: https://fetch.spec.whatwg.org/ https://fetch.spec.whatwg.org/, and had been for a while. I don't think it is so strange for node to incorporate it as part of their standard lib as well. 1. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
- sealthedeal 5y agoFWIW, this was the answer I was hoping to get, grabbed from a separate comment :) "With fetch available in node, we have a single, standardised, promise-based HTTP client Interface available on all (more or less common) JavaScript platforms. This is great news for an ecosystem traditionally extremely fragmented and may lead the way to more consolidation in the JS library space. "