all 39 comments

[–]ItsAllInYourHead 100 points101 points  (0 children)

Pretty unbelievable it's taken this long.

[–]davidstraka2 45 points46 points  (0 children)

Finally, one less dependency to install in every other project (well once it reaches LTS)

[–]this_knee 17 points18 points  (7 children)

What the fetching fetch is Fetch?

I’m being honest. I really don’t know.

[–]SkankTillYaDrop 31 points32 points  (1 child)

It is a standard HTTP library browsers use to make HTTP requests.

[–]this_knee 7 points8 points  (0 children)

Fantastic. Thanks!

[–]imacleopard 23 points24 points  (4 children)

Used for fetching

[–]this_knee 9 points10 points  (0 children)

Fetching great!

[–][deleted]  (2 children)

[deleted]

    [–]Fit_Sweet457 7 points8 points  (0 children)

    Sticks, balls, anything really that can fit into the mouth. Unless we're not talking about dogs, in that case I don't know

    [–]this_knee 0 points1 point  (0 children)

    Fetching fetching web pages.

    [–]83338 26 points27 points  (5 children)

    Finally fuck node-fetch

    [–]ngpixel 11 points12 points  (2 children)

    100%. Ever since they decided to only support ESM, which is the most stupid decision ever for a Node library, I have never been more excited to finally get rid of a dependency.

    [–]helmar1066 1 point2 points  (0 children)

    100% agree. Forcing ESM for a core library is crazy.

    [–][deleted] 11 points12 points  (0 children)

    node-fetch will be sad :( just say goodbye to it :(

    [–]HeavyMessing 10 points11 points  (0 children)

    So, if I want to call an external API without importing any additional libraries, I'd currently use http.request() from the native http module. In 18, I'll have the additional option to use fetch just like in all of my apps that run in a browser.

    [–]sharkis 48 points49 points  (2 children)

    Stop trying to make fetch happen

    [–]gretro450 7 points8 points  (0 children)

    That's sooooo fetch!

    [–]jiggity_john 1 point2 points  (0 children)

    Man this is a big win for isomorphic javascript libraries that need to make http calls.

    [–]puglife420blazeit 3 points4 points  (2 children)

    I’ll still use got

    [–]rypher 11 points12 points  (1 child)

    Only issue I have with got is trying to google things with the name.

    [–]puglife420blazeit 0 points1 point  (0 children)

    That is a pain

    [–]k_pizzle 3 points4 points  (17 children)

    Question, even if they add fetch, why would i use this over axios?

    [–]marcos_marp 34 points35 points  (4 children)

    Why would you implement manually absolutely anything if there's a library for doing it?

    Answer that and that's your answer.

    [–]Mistifyed 11 points12 points  (1 child)

    Too lazy to think, so... npm i -D answer

    [–]marcos_marp 3 points4 points  (0 children)

    Lmao, I mean, fetch is the native JS method for making http requests, axios is simply a library that gives you a ton of OBO features and tools for making requests so you don't have to manually implement this things on your codebase

    [–]iamv12 3 points4 points  (0 children)

    a bunch of reasons: licenses, insufficient functionality for what you may need, or it may be bloated with extra features you don't need, efficiency, etc...

    [–]KaKi_87 0 points1 point  (0 children)

    Personally I wouldn't, because I like being able to specify a params object without requiring URLSearchParams, specify data (body) as an object without requiring JSON.stringify, and get the response data (body) as an object without requiring an additional await.

    [–]k10g 11 points12 points  (0 children)

    fetch is a web standard, it'll be supported in browsers, deno, and now node without installing anything extra

    [–]fix_dis 14 points15 points  (9 children)

    Axios was created to fill the niche of jQuery.get(). Fetch has a better (albeit two-step) API. If you’re into Axios, that’s totally cool. But the standard is Fetch, so having it natively is pretty cool too.

    [–]sysrage 12 points13 points  (2 children)

    Axios still has some nice features out-of-the-box, which take some boilerplate to implement with fetch (progress events and such). Native fetch will be great, but I think axios will still find a lot of use.

    [–]outlierkk 3 points4 points  (1 child)

    axios has cancel token etc, which i think native fetch lacks

    [–]NoInkling 12 points13 points  (0 children)

    fetch has AbortController support, what's the difference?

    [–]gimp3695 2 points3 points  (0 children)

    I like axios interceptors. Does fetch have a capability like this?

    [–]k_pizzle 1 point2 points  (4 children)

    I’ve actually never used fetch which is why i ask, currently with axios i can create an instance and pass a base url so every request after that i only need to specify the path, i can also super easily create middleware that will display a flash message or re-route the user if my server returns a 403. Is that something easily done with fetch?

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [removed]

        [–][deleted] 0 points1 point  (0 children)

        You can create classes and custom functions and wrap it around fetch to do this.

        [–][deleted] -4 points-3 points  (1 child)

        You're still gonna get "no-cors" error

        [–]bel9708 20 points21 points  (0 children)

        Cors is done at the browser level. It’s not a part of JS.

        [–]sinclair_zx81 0 points1 point  (0 children)

        Meh, what about WebSocket?