Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

axios
http
request
fetch

What is Axios?

Educative Answers Team

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 ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring