Differences between Fetch and Axios.

Isaac Avilez
2 min readJan 13, 2021

In this blog I will be talking about some differences between both fetch and axios. At the end, as developers, it’s up to you which one you want to use, but I will hopefully clear up some stuff for you by the end of this blog regarding both fetch and axios.

Let’s start off with some of the basic syntax for the both of them. To make a simple fetch request:

fetch('api')
.then((response) => {
// Code for handling the response.
})
.catch((error) => {
// Some code for error handling.
});

Here there is a simple request with Axios:

axios.get('url')
.then((response) => {
// Code for handling the response.
})
.catch((error) => {
// Some code for error handling.
})

Some differences between Axios and Fetch is:

  • Axios Fetch Axios has url in request object, meanwhile Fetch has no url in request object.
  • Axios automatically performs the transformation of JSON data, as opposed to fetch where it’s a two step process when handling JSON data. First is you make the actual request, then proceed by calling the .json() method on the response.
  • Axios allows cancelling request and request timeout; fetch doesn’t.
  • Axios request is OK when status is 200 and statusText is ‘OK’, compared to fetch, where the request is OK only when the response object contains the OK property.
  • Talking about objects, Axios uses the data property as opposed to fetch where it uses the data property.

I hope this blog has helped you understand more of Axios compared to fetch, and will help you in your programming endeavors!

--

--