If your app is a single page app and heavily interacts with backend through APIs you may notice that most of the methods require common user data to pass to backend. For example a token header or custom cookies etc. If you use fetch then for every possible endpoint you've to write all those things for each fetch request. However, in axios you can create a session with commonly required data that needs to be sent, and in your actual call to endpoint you only add additional information that is required.
I've not used axios more than this, so I would also like to know more points from others.
Awesome. Thanks for sharing. Indeed, my team is using fetch() but we do have the requirement you say. Makes me wonder how they did it with fetch(). Maybe I should check their code. I fear I'll find a mess! Hehe.
So this sounds like a solid point in favor of Axios.
Thanks for stopping by. some interesting points in that table, although one is clearly wrong, as fetch()can be cancelled through an AbortController object. Also the first one in the table sounds suspicious because fetch()'s Request object does have the url property.
In my opinion fetch has gotten really good over the years and there's no real use case for axios. I think people just use it because they are used to it.
If your app is a single page app and heavily interacts with backend through APIs you may notice that most of the methods require common user data to pass to backend. For example a token header or custom cookies etc. If you use fetch then for every possible endpoint you've to write all those things for each fetch request. However, in axios you can create a session with commonly required data that needs to be sent, and in your actual call to endpoint you only add additional information that is required.
I've not used axios more than this, so I would also like to know more points from others.
Awesome. Thanks for sharing. Indeed, my team is using
fetch()but we do have the requirement you say. Makes me wonder how they did it withfetch(). Maybe I should check their code. I fear I'll find a mess! Hehe.So this sounds like a solid point in favor of Axios.
FYI, there are apiClient out there uses fetch, I personally use Wretch daily
dev.to/marklai1998/why-im-ditching...
res.json()everywhereAlso, check this geeksforgeeks link
Thanks for stopping by. some interesting points in that table, although one is clearly wrong, as
fetch()can be cancelled through anAbortControllerobject. Also the first one in the table sounds suspicious becausefetch()'s Request object does have the url property.In any case, I'll tabulate some more. Cheers!
Didn't know, thanks for sharing!
I haven't used axios in 5+ years now. A small wrapper around fetch is all you really need.
FYI, there are apiClient out there uses fetch, I personally use Wretch daily
dev.to/marklai1998/why-im-ditching...
In my opinion
fetchhas gotten really good over the years and there's no real use case for axios. I think people just use it because they are used to it.Alright. Fair enough. Tabulated the reason. Many thanks!
Mainly about master configuration. It's all about the DRY principle all over again.