Back to Axios

Getting Started

posts/en/intro.md

latest2.1 KB
Original Source

What is Axios?

Axios is a promise-based HTTP Client for node.js and the browser. It is isomorphic (= it can run in the browser and node.js with the same codebase). On the server-side it uses the native node.js http module, while on the client (browser) it uses XMLHttpRequest.

Features

  • Make XMLHttpRequest from the browser
  • Make http requests from node.js
  • Supports the Promise API
  • Intercept request and response
  • Transform request and response data
  • Cancel requests
  • Timeouts
  • Query parameters serialization with support for nested entries
  • Automatic request body serialization to:
    • JSON (application/json)
    • Multipart / FormData (multipart/form-data)
    • URL encoded form (application/x-www-form-urlencoded)
  • Posting HTML forms as JSON
  • Automatic JSON data handling in response
  • Progress capturing for browsers and node.js with extra info (speed rate, remaining time)
  • Setting bandwidth limits for node.js
  • Compatible with spec-compliant FormData and Blob (including node.js)
  • Client side support for protecting against XSRF

Installing

Using npm:

bash
$ npm install axios

Using bower:

bash
$ bower install axios

Using yarn:

bash
$ yarn add axios

Using pnpm:

bash
$ pnpm add axios

Using jsDelivr CDN:

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

Using unpkg CDN:

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

Prebuilt CommonJS modules for direct importing with require (if your module bundler failed to resolve them automatically)

js
const axios = require('axios/dist/browser/axios.cjs'); // browser
const axios = require('axios/dist/node/axios.cjs'); // node