MCPcopy Create free account
hub / github.com/axios/axios

github.com/axios/axios

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.6.4 ↗ · + Follow · compare 6 versions
370 symbols 960 edges 150 files 39 documented · 11% updated 2d agov1.20.0 · 2026-08-24★ 109,19447 open issues

Browse by type

Functions 302 Types & classes 68
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Platinum sponsors

     <img width="400px" src="https://github.com/axios/axios/assets/4814473/75c37f4d-36e6-44f5-a068-3edd77c00a10" />

Alloy is the integration development platform that makes it simple and

fast for SaaS companies to launch critical user-facing integrations.

Gold sponsors

  <img width="200px" src="https://github.com/axios/axios/assets/4814473/b6a9a7bc-9fb1-4b9b-909f-1b4bee1fd142" />

API-first authentication, authorization, and fraud prevention

   <a href="https://stytch.com?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=website-link&utm_campaign=axios-http"><b>Website</b></a> •
   <a href="https://stytch.com/docs?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=docs-link&utm_campaign=axios-http"><b>Documentation</b></a> • <a href="https://github.com/stytchauth/stytch-node?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=node-sdk&utm_campaign=axios-http"><b>Node.js Backend SDK</b></a>

Promise based HTTP client for the browser and node.js

<a href="https://axios-http.com/"><b>Website</b></a> •
<a href="https://axios-http.com/docs/intro"><b>Documentation</b></a>

npm version CDNJS Build status Gitpod Ready-to-Code code coverage install size npm bundle size npm downloads gitter chat code helpers Known Vulnerabilities

Table of Contents

Features

  • 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
  • 🆕 Automatic data object serialization to multipart/form-data and x-www-form-urlencoded body encodings
  • Client side support for protecting against XSRF

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 11 ✔

Browser Matrix

Installing

Package manager

Using npm:

$ npm install axios

Using bower:

$ bower install axios

Using yarn:

$ yarn add axios

Using pnpm:

$ pnpm add axios

Once the package is installed, you can import the library using import or require approach:

import axios, {isCancel, AxiosError} from 'axios';

You can also use the default export, since the named export is just a re-export from the Axios factory:

import axios from 'axios';

console.log(axios.isCancel('something'));
````

If you use `require` for importing, **only default export is available**:

```js
const axios = require('axios');

console.log(axios.isCancel('something'));

For cases where something went wrong when trying to import a module into a custom or legacy environment, you can try importing the module package directly:

const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
// const axios = require('axios/dist/node/axios.cjs'); // node commonJS bundle (ES2017)

CDN

Using jsDelivr CDN (ES5 UMD browser module):

<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>

Using unpkg CDN:

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

Example

Note: CommonJS usage
In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require(), use the following approach:

import axios from 'axios';
//const axios = require('axios'); // legacy way

// 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);
  })
  .finally(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);
  })
  .finally(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);
  }
}

Note: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.

Performing a POST request

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

Performing multiple concurrent requests

function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

Promise.all([getUserAccount(), getUserPermissions()])
  .then(function (results) {
    const acct = results[0];
    const perm = results[1];
  });

axios API

Requests can be made by passing the relevant config to axios.

axios(config)
// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});
// GET request for remote image in node.js
axios({
  method: 'get',
  url: 'https://bit.ly/2mTM3nY',
  responseType: 'stream'
})
  .then(function (response) {
    response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
axios(url[, config])
// Send a GET request (default method)
axios('/user/12345');

Request method aliases

For convenience, aliases have been provided for all common request methods.

axios.request(config)
axios.get(url[, config])
axios.delete(url[, config])
axios.head(url[, config])
axios.options(url[, config])
axios.post(url[, data[, config]])
axios.put(url[, data[, config]])
axios.patch(url[, data[, config]])
NOTE

When using the alias methods url, method, and data properties don't need to be specified in config.

Concurrency (Deprecated)

Please use Promise.all to replace the below functions.

Helper functions for dealing with concurrent requests.

axios.all(iterable) axios.spread(callback)

Creating an instance

You can create a new instance of axios with a custom config.

axios.create([config])
const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

Instance methods

The available instance methods are listed below. The specified config will be merged with the instance config.

axios#request(config)
axios#get(url[, config])
axios#delete(url[, config])
axios#head(url[, config])
axios#options(url[, config])
axios#post(url[, data[, config]])
axios#put(url[, data[, config]])
axios#patch(url[, data[, config]])
axios#getUri([config])

Request Config

These are the available config options for making requests. Only the url is required. Requests will default to GET if method is not specified.

``js { //url` is the server URL that will be used for the request url: '/user',

// method is the request method to be used when making the request method: 'get', // default

// baseURL will be prepended to url unless url is absolute. // It can be convenient to set baseURL for an instance of axios to pass relative URLs // to methods of that instance. baseURL: 'https://some-domain.com/api/',

// transformRequest allows changes to the request data before it is sent to the server // This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE' // The last function in the array must return a string or an instance of Buffer, ArrayBuffer, // FormData or Stream // You may modify the headers object. transformRequest: [function (data, headers) { // Do whatever you want to transform the data

return data;

}],

// transformResponse allows changes to the response data to be made before // it is passed to then/catch transformResponse: [function (data) { // Do whatever you want to transform the data

return data;

}],

// headers are custom headers to be sent headers: {'X-Requested-With': 'XMLHttpRequest'},

// params are the URL parameter

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 223
Method 79
Interface 39
Class 28
Enum 1

Languages

TypeScript100%

Modules by API surface

index.d.ts52 symbols
test/manual/promise.js42 symbols
lib/utils.js35 symbols
lib/core/AxiosHeaders.js28 symbols
bin/GithubAPI.js23 symbols
test/module/typings/esm/index.ts10 symbols
lib/adapters/http.js10 symbols
lib/helpers/AxiosTransformStream.js9 symbols
test/unit/adapters/http.js8 symbols
test/module/typings/cjs/index.ts8 symbols
lib/helpers/toFormData.js8 symbols
bin/RepoBot.js8 symbols

Dependencies from manifests, versioned

@babel/core7.18.2 · 1×
@babel/preset-env7.18.2 · 1×
@commitlint/cli17.3.0 · 1×
@commitlint/config-conventional17.3.0 · 1×
@release-it/conventional-changelog5.1.1 · 1×
@rollup/plugin-babel5.3.1 · 1×
@rollup/plugin-commonjs15.1.0 · 1×
@rollup/plugin-json4.1.0 · 1×
@rollup/plugin-multi-entry4.0.0 · 1×
@rollup/plugin-node-resolve9.0.0 · 1×
@types/node18.11.3 · 1×

For agents

$ claude mcp add axios \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page