What is difference between Axios and Fetch? [closed]
why do people use axios instead of fetch
Axios or in built fetch
Fetch vs Axios?
Does Axios use fetch() under the hood?
Can I use Axios or Fetch with React Query?
Why do developers still prefer Axios even though Fetch is now built into Node.js?
Videos
I'm starting a new project and can't decide between Axios and Fetch for handling HTTP requests. Both have their merits, but I’m looking for some community input.
Axios: seems great for older browser support and easy features.
fetch: is lighter and native but needs more setup.
Which do you prefer, Axios or Fetch, and why? Any particular reasons to choose one over the other based on your experience?
Fetch and Axios are very similar in functionality, but for more backwards compatibility Axios seems to work better (fetch doesn't work in IE 11 for example, check this post)
Also, if you work with JSON requests, the following are some differences I stumbled upon with.
Fetch JSON post request
let url = 'https://someurl.com';
let options = {
method: 'POST',
mode: 'cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({
property_one: value_one,
property_two: value_two
})
};
let response = await fetch(url, options);
let responseOK = response && response.ok;
if (responseOK) {
let data = await response.json();
// do something with data
}
Axios JSON post request
let url = 'https://someurl.com';
let options = {
method: 'POST',
url: url,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8'
},
data: {
property_one: value_one,
property_two: value_two
}
};
let response = await axios(options);
let responseOK = response && response.status === 200 && response.statusText === 'OK';
if (responseOK) {
let data = await response.data;
// do something with data
}
So:
- Fetch's body = Axios' data
- Fetch's body has to be stringified, Axios' data contains the object
- Fetch has no url in request object, Axios has url in request object
- Fetch request function includes the url as parameter, Axios request function does not include the url as parameter.
- Fetch request is ok when response object contains the ok property, Axios request is ok when status is 200 and statusText is 'OK'
- To get the json object response: in fetch call the json() function on the response object, in Axios get data property of the response object.
They are HTTP request libraries...
I end up with the same doubt but the table in this post makes me go with isomorphic-fetch. Which is fetch but works with NodeJS.
Screenshot for convenience

As i know it can basically do the same stuff for example api calls, post/get requests to server. Then why should i use a library for this when fetch is that easy to lern. If the only alternative were there goofy XmlHttpRequests i would say its ok to use a Library, but thats the reason why we have ajax with jquery