axios – a promise based HTTP client

Axios is a promise based HTTP client for the browser and node.js.

axios GitHub

Installation

npm install axios

or add to the web page

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

Single request

// Make a request 
axios.get('http://localhost:4000/api/usersTop')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Performing multiple concurrent requests

function getTopUsers() {
  return axios.get('http://localhost:4000/api/usersTop');
}

function getComments() {
  return axios.get('http://localhost:4000/api/comments');
}

axios.all([getTopUsers(), getComments()])
  .then(axios.spread(function (users, comments) {
    // Both requests are now complete
  }));