Skip to content

Implement window.fetch into core #19393

Description

@thecodingdude

Edit: Fetch is available through the --experimental-fetch flag in Node. This is still very new :]


Edit: please note that this issue is pretty old and a lot of the information in the first few comments isn't up to date - for current status please see #19393 (comment) .


https://github.com/bitinn/node-fetch

It would make sense if window.fetch was implemented into core. it seems to be a stable enough API that would make a good candidate for inclusion. Not sure what the process is from here but thought I'd raise an issue :)

Activity

  1. jasnell commented on Mar 16, 2018

    @jasnell
    Member

    this has come up from time to time but has not had much traction just yet. Let's see what folks think tho :-)

  2. added
    httpIssues and PRs related to the http subsystem.
    http2Issues and PRs related to the http2 subsystem.
    on Mar 16, 2018
  3. devsnek commented on Mar 16, 2018

    @devsnek
    Member

    bradley and i were discussing this in a roundabout way on the subject of importing from urls. if that feature was introduced (and i think in general we do want it) we would need to implement this: https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script which uses the fetch spec. as another note if this was added in core i would want to pull in an existing c++ implementation from one of the browsers. however at a bare minimum node will definitely be adding Request and Response objects, it just might not add a function called fetch

  4. mscdex commented on Mar 16, 2018

    @mscdex
    Contributor

    -1 this kind of higher-level functionality is best left to userland

  5. guybedford commented on Mar 16, 2018

    @guybedford
    Contributor

    This would definitely be useful in simple cross-platform APIs and I think is what a lot of people use node-fetch for already. Also it would be nice if HTTP/1 v HTTP/2 negotiation can be handled automatically like in browsers as well.

  6. styfle commented on Mar 17, 2018

    @styfle
    SponsorMember

    I would love this! ❤️

    Isomorphic JS is one of the big reasons people who start with JS on the front end, eventually pick up Node.js on the backend.

    You get to run the exact same function in the browser and the server and the one place of contention I keep finding is window.fetch.

    Some of the code that runs on the server and client needs to make HTTP requests to another server (think microservices with server side rendering and client side rendering).

    One case for bringing it into core is that making HTTP requests (client) is closely tied to responding to HTTP requests (server).

    And we now have isomorphic URL parsing so now all we need is fetch! Let’s make fetch happen!

  7. mikemaccana commented on Mar 17, 2018

    @mikemaccana
    Contributor

    Fetch is 'low level' according to it's author and major supporter hence missing a bunch of features like support for content types, JSON not being default, no query string encoding. Apps that need a high level quality HTTP client available in all JavaScript environments can continue using superagent.

  8. devsnek commented on Mar 17, 2018

    @devsnek
    Member

    @mikemaccana the fetch we are talking about is https://fetch.spec.whatwg.org/ and i don't think its appropriate to be plugging other http libraries

  9. mikemaccana commented on Mar 17, 2018

    @mikemaccana
    Contributor

    @devsnek Yes I know, that's the one I was specifically referring to. I don't have any particular enjoyment of superagent asides from it being:

    • a full featured HTTP client
    • available in node and the browser
    • more popular than fetch
    • has JSON as a default
    • encodes query strings
    • uses content types to determine response body
    • uses HTTP verbs as method names, so you can happily .get() and .post() things rather than 'fetching with method POST' which is a somewhat odd mental model

    If fetch supported these I'd suggest it be included in node. To repeat: I've asked fetch's author and main proponent, Jake Archibald, why it doesn't support these things and it's stated that fetch is designed to be a low level API and things like sensible defaults can/should be added by higher level APIs. As a result I see no reason to use fetch in node, or in the browser.

  10. joyeecheung commented on Mar 18, 2018

    @joyeecheung
    Member

    @mikemaccana

    These are actually desirable properties for the argument of including fetch in Node.js core, if we want to keep the core low-level and small. I believe we will need to eventually provide a promisified API for http/http2 anyway, and fetch as an existing spec for a similar set of low-level functionality as our http is something worth considering. In my experience the missing pieces in fetch feels pretty similar to the missing pieces in Node.js's http, the major difference is that you have a spec'ed API to count on.

    Also I kind of doubt the "more popular than fetch" part, I don't think there are as many people using super-agent in the browser as in Node, given that fetch simply exists in the browser (modulo situations needing polyfills)?

    Although, before we start implementing fetch, I believe we will need to introduce the stream API in the browser? Is introducing yet another stream in Node.js on the table?

    The one time I've been forced to resort to XHR in the browser was when I needed progress, although I think with the browser's ReadableStreams it's possible to do the same thing with an API that's a bit awkward (res.body.read().byteLength)- if I'd implement progress in Node.js I think I'll need to use chunk.byteLength from the chunk being emitted in the data event, which is where the difference between the two streams start to matter.

    Also, the fetch spec does not seem to include timeout or agents (yet?) at the moment, there might be more functionalities missing compared to our existing http API. For reference, node-fetch seems to implement these non-standard options. Again, not sure if our implementation should implement non-standard functionalities even if they supply the missing pieces compared to the old API.

  11. joyeecheung commented on Mar 18, 2018

    @joyeecheung
    Member

    also cc @TimothyGu you might be interested?

  12. joyeecheung commented on Mar 18, 2018

    @joyeecheung
    Member

    @thecodingdude

    entirely disagree; Node uses v8, and by extension, should implement as many as v8 features as possible that make sense. fetch is one of those where developers wouldn't need to npm install request or node-fetch which are very popular libraries so this functionality warrants being in core.

    Technically fetch is not a v8 feature though, it's an API spec'ed by WHATWG, whereas v8 implements ECMA-262, a spec by ECMA TC39 - if v8 implemented fetch then there would not be this feature request, because we basically just expose what v8 exposes.

    BTW: I don't think we are talking about pulling npm packages into the core? Rather, we are talking about implementing the spec on our own and pulling in the WPT to test compliance, possibly with a bunch of code written in C++, much like what we did for WHATWG URL.

  13. mikemaccana commented on Mar 18, 2018

    @mikemaccana
    Contributor

    @thecodingdude the continued popularity of non-fetch libraries isn't a personal opinion, it is a fact - superagent had 1.6 million downloads this week . Nor is the lack of reasonable high-level defaults in fetch: again (again) that is acknowledged by fetch's author. Please don't reframe verifiable objective technical facts as irrelevant subjective opinions because you do not like them.

    please don't plug other libraries here, they are irrelevant to our discussion.

    developers wouldn't need to npm install request or node-fetch

    😂👍

  14. 249 remaining items

  15. voxpelli commented on Sep 15, 2021

    @voxpelli

    If the conclusion here is that when/if window.fetch is going to be implemented in core, then it's going to be through undici, then I guess this issue can be closed in favor of #38533 as that one is discussing how to move forward with the future of the Node HTTP Client and how undici fits into that and how it can be the way forward.

    It in turn depends on nodejs/TSC#1041 / https://github.com/nodejs/node/discussions/39779 which discusses the principles around what belongs in core or not.

    Anyone of a different conclusion?

  16. mcollina commented on Sep 15, 2021

    @mcollina
    SponsorMember

    I concur with @voxpelli

  17. added a commit that references this issue on Feb 1, 2022
  18. SimenB commented on Feb 1, 2022

    @SimenB
    Member

    I never thought to see the day. Thank you! ❤️

  19. sillyslux commented on Feb 1, 2022

    @sillyslux

    Is there still time to rename it? In electron we suddenly have two different fetches right next to one another. If nobody else, i know i'll be confused one day.

  20. repugraf commented on Feb 2, 2022

    @repugraf

    We all know it takes effort to make things work and not break anything.
    You had to overcome pressure from a lot of ungrateful people not seeing the full picture.
    So thank you, guys. We all appreciate your hard work.
    Keep it up!

  21. mbodm commented on Feb 2, 2022

    @mbodm

    We all know it takes effort to make things work and not break anything.
    You had to overcome pressure from a lot of ungrateful people not seeing the full picture.
    So thank you, guys. We all appreciate your hard work.
    Keep it up!

    Sign that!

    Thx for all your hard work, to keep Node going. Thx a lot!

  22. added a commit that references this issue on Feb 8, 2022
  23. added a commit that references this issue on Apr 21, 2022
  24. added a commit that references this issue on May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.httpIssues and PRs related to the http subsystem.http2Issues and PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions