Axios is a promise-based HTTP client library that works in both browser and Node.js environments. It provides a unified API for making HTTP requests with support for interceptors, automatic data transformation, request cancellation, and cross-platform compatibility through an adapter-based architecture.
This document provides a high-level introduction to axios's purpose, features, architecture, and distribution model. For detailed information about specific subsystems, see the linked pages throughout this document.
Axios abstracts the differences between browser XMLHttpRequest, Node.js http modules, and the modern Fetch API into a single, consistent interface. The library handles:
Related Pages:
The following table summarizes axios's primary capabilities:
| Feature | Description | Primary Implementation |
|---|---|---|
| Cross-Platform Requests | Works in browsers, Node.js, Deno, and Bun | package.json18-34 |
| Promise-Based API | Native Promise support for async operations | index.d.ts186-210 |
| Request/Response Interceptors | Middleware-like hooks for transformation | index.d.ts179-182 |
| Automatic JSON Handling | Serializes and parses JSON automatically | index.js20 |
| Request Cancellation | Cancel requests via AbortController or CancelToken | index.d.ts163-174 |
| Form Serialization | Auto-serialize to FormData or URLEncoded | index.js17-20 |
| HTTP/2 Support | HTTP/2 protocol support in Node.js | CHANGELOG.md61 |
| Proxy Support | HTTP/HTTPS proxy configuration | index.d.ts168-173 |
| TypeScript Support | Complete type definitions | index.d.ts1-250 |
Sources: package.json4-10 index.js6-24 index.d.ts1-250
Axios is structured in distinct layers, each with specific responsibilities. The following diagram shows the main architectural components and their relationships:
Title: Axios High-Level Architecture
Component Descriptions:
Sources: index.js6-24 index.d.ts1-250 package.json35-49
The following diagram illustrates how a request flows through the axios system from user code to final response:
Title: Request Dispatch Sequence
Key Lifecycle Stages:
getAdapter index.js21 index.d.ts159AxiosError with request context and status codes index.d.ts128-168Sources: index.d.ts128-210 index.js21-23
Axios supports multiple JavaScript environments through its adapter system:
Title: Environment-Based Adapter Selection
Adapter Selection Logic:
follow-redirects package.json142Sources: package.json12-63 package.json142-146
Axios is distributed in multiple formats to support different module systems and environments:
Title: Module Distribution Map
Package.json Exports Configuration:
The library uses conditional exports to route different environments to appropriate builds package.json12-49:
| Environment | Build | Entry Point |
|---|---|---|
| Node.js | CommonJS | ./dist/node/axios.cjs |
| Browser | CommonJS | ./dist/browser/axios.cjs |
| React Native | ESM | ./dist/esm/axios.js |
| Bun | Node.js CJS | ./dist/node/axios.cjs |
| TypeScript (CJS) | Type Definitions | ./index.d.cts |
| TypeScript (ESM) | Type Definitions | ./index.d.ts |
Sources: package.json1-117 index.js1-46
Current version: 1.18.1 (lib/env/data.js1 package.json3)
Core Dependencies:
follow-redirects ^1.16.0 package.json142form-data ^4.0.6 package.json143https-proxy-agent ^5.0.1 package.json144proxy-from-env ^2.1.0 package.json145Sources: package.json3 lib/env/data.js1 CHANGELOG.md3