Trusted answers to developer questions

What is Axios?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Axios is a lightweight HTTP client based on the XMLHttpRequests service. It is similar to the Fetch API and is used to perform HTTP requests.

svg viewer

Installing Axios

The following command can be used for installing axios using npm:

npm install axios

Making an HTTP GET request

Axios can be used to perform a simple GET request. The syntax for this is​:

axios({
  url:'https://www.educative.io/',
  method: 'get'
})

Making an HTTP POST request

Axios can similarly be used to perform a simple POST request. We can also send parameters in an object using the POST request. The syntax for this is:

axios({
  method: 'post',
  url: '/signup',
  data: {
    user: 'abcd1234',
    pass: 'pwd1234'
  }
})

Advantage of Axios over Fetch API

  • supports older browsers
  • has a way to abort a request
  • has a way to set a response timeout
  • has built-in CSRF protection
  • supports upload progress
  • performs automatic JSON data transformation.

RELATED TAGS

axios
http
request
fetch
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?