

Unlike the Fetch API, where you have to check the status code and throw the error yourself. Axios throws 400 and 500 range errors for you. then() callback to access your requested JSON data.

Axios has function names that match any HTTP methods.Or perform tedious tasks like converting your request body to a JSON string. Unlike alternatives such as the Fetch API, you often don't need to set your headers. It has good defaults to work with JSON data.Here are five reasons why you should use Axios as your client to make HTTP requests: There are a number of different libraries you can use to make these requests, so why choose Axios? This could be an external API or your own backend Node.js server, for example.īy making a request, you expect your API to perform an operation according to the request you made.įor example, if you make a GET request, you expect to get back data to display in your application.
#Axios defaults how to
