How to install Axios

Created

Axios is a client HTTP API based on the XMLHttpRequest interface provided by browsers.

Axios depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can polyfill.

Installation

You can download the latest version of Axios from the GitHub releases or use a Axios CDN.

You can install Axios using:

Cloning a repository

You can clone a repository from GitHub.com to your local computer.
Cloning with HTTPS URLs
git clone https://github.com/axios/axios.git
Cloning with SSH URLs
git clone [email protected]:axios/axios.git
Cloning with GitHub CLI
gh repo clone axios/axios

Install via NPM package

Run the following command to locally install the package and its dependencies with NPM.
Next Version:0.20.0-0
Publish Time:2020-07-16 00:07:30
Unpacked Size:357.57 kB
Downloading and installing packages locally
npm i axios
npm install axios
yarn add axios
Downloading and installing packages globally
npm i -g axios
yarn global add axios
Install Specific Version of a Package
npm install [email protected]
Bower
bower install axios

Example

GET: - Performing a GET request.

const axios = require('axios');

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });

POST: - Performing a POST request.

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });