Promise based HTTP client for the browser and node.js
New axios docs website: click here
- Features
- Browser Support
- Installing
- Example
- Axios API
- Request method aliases
- Concurrency (Deprecated)
- Creating an instance
- Instance methods
- Request Config
- Response Schema
- Config Defaults
- Interceptors
- Handling Errors
- Cancellation
- Using application/x-www-form-urlencoded format
- Semver
- Promises
- TypeScript
- Resources
- Credits
- License
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against XSRF
Latest âś” | Latest âś” | Latest âś” | Latest âś” | Latest âś” | 11 âś” |
Using npm:
$ npm install axios
Using bower:
$ bower install axios
Using yarn:
$ yarn add axios
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Using unpkg CDN:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require()
use the following approach:
const axios = require('axios').default;
// axios.<method> will now provide autocomplete and parameter typings
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
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}