Now I know what you are thinking... puppies are cute right?
No, Okay.
It's a little overkill to always reach out for a third-party library to ha...
For further actions, you may consider blocking this person and/or reporting abuse
I have to desagree on some points because axios is a much more powerfull request layer.
All these points explain why so many of us prefer using a higher layer library like axios.
Hi! I totally agree with you.
I've noticed the tone I used was a little condescending. Sorry about that. I've made an update clarifying the intention of writing the article and some of the shortcomings of fetch. 🙂
Didn't mean to rattle you😅
Hello Alex,
No worries. I was not bothered at all by the tone of your post.
You have written a good article, with a lot of insights for developpers.
Keep it up.
Yeh agreed. Fetch isn't a replacement at all for axios, axios simply provides so much more than just fetching something. +1 for interceptors I was going to mention but you beat me too it :)
Cave painting😂😂. Woow!
Yep, there is a reason why SSR frameworks still favor Nuxt. It's hell with fetch, there's is always calls responding weirdly.
How does isormophic-unfetch perform in SSR using Nuxt?
That's a good question! Never tried it, but seems very attractive. Very minimalist.
Zapper has a nice approach: replacing fetch or this.fetch as needed (being a compiler it's easy enough to do). Effectively, you're just writing you're only using fetch.
Nice article but beware of the
response.json()
call before checkingreponse.ok
, it may get you or anyone copying your example in trouble!I found this video by Joel Thoms to explain clearly the issue: youtube.com/watch?v=aIboXjxo-w8
Learnt something new today! Thank you for sharing
cross-fetch would be worth considering these days github.com/lquixada/cross-fetch
There's one specific case I'd like to point out where XMLHttpRequest could be preferred, and is regarding cancellations.
When you abort a fetch call, you are aborting the network call, but the Promise itself is not canceled because Promises don't support cancelation. As you can see, the actual behavior is that the promise throws.
This is fine for most cases and practically all product development, but in very specific and extreme circumstances this might not be desired because Promise ticks are actually expensive and can clog the stack, which can end up having a consequence in the execution flow of the program.
A callback-oriented API that doesn't rely on Promises doesn't have this drawback, and that just wouldn't be possible to do with fetch, but is possible to do with XMLHttpRequest.
Thanks I was actually using axios yesterday and wondering how to replace with fetch.
Why don't you open the post with dogs are cute instead of cows are cute? Otherwise it seems like a distraction
I'm glad you liked it. Sure, I'll make the update 😉
Wow that's amazing!
How about interceptors?
Does fetch support it?
No. Fetch is very minimal and not a replacement for axios at all. Unless you are just grabbing a few things
So glad to see this so well received by the community!