axios
Axios is a promise-based HTTP client for the browser and Node.js that provides an elegant and powerful API for making HTTP requests. It features automatic JSON …
Installation
npm install axios
yarn add axios
pnpm add axios
Import
import axios from 'axios';
Quick Example
const response = await axios.get('/api/users');
console.log(response.data);
await axios.post('/api/users', {
name: 'John',
email: '[email protected]',
});About axios
Axios is a promise-based HTTP client for the browser and Node.js that provides an elegant and powerful API for making HTTP requests. It features automatic JSON transformation for request and response data, request and response interceptors for global handling of authentication headers and error responses, and built-in CSRF protection through XSRF token support. Axios supports request cancellation using AbortController, timeout configuration, upload and download progress events, and automatic request retry through community plugins. The library works identically in both browser and Node.js environments by using XMLHttpRequest in browsers and the http module in Node.js. Axios instances can be created with custom default configurations for base URLs, headers, and timeout values, making it easy to configure different API clients for different services. The interceptor system allows global request and response transformation, which is commonly used for attaching authentication tokens, refreshing expired tokens, and handling error responses consistently. Axios remains one of the most downloaded npm packages despite the growth of the native Fetch API.
Quick Facts
| Package | axios |
| Category | HTTP |
| Weekly Downloads | 45M+ |
| License | MIT |
| Install | npm install axios |
Related Packages
Node-fetch is a lightweight module that brings the browser's Fetch API to Node.js, providing a famil…
Got is a human-friendly and powerful HTTP request library for Node.js that provides an extensive fea…
Ky is a tiny and elegant HTTP client based on the browser Fetch API, providing a more convenient API…
SuperAgent is a progressive HTTP request library for Node.js and the browser that provides a flexibl…
Undici is a high-performance HTTP/1.1 client for Node.js, developed by the Node.js team and serving …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.