API Reference

Axios

Promise-based HTTP client for browser and Node.js with interceptors, transforms, and automatic JSON parsing.

Official Documentation ↗
CompatibilityThis documentation covers version v1.7. Check the official docs for the latest API surface.

Installation

npmnpm install axios
pnpmpnpm add axios
yarnyarn add axios

Methods

Axios is a promise-based HTTP client that works in both browser and Node.js environments. It provides a simple API for making HTTP requests with automatic JSON transformation, request/response interceptors, error handling, and cancellation support.

Key Features

  • Isomorphic: Same API for browser (XMLHttpRequest) and Node.js (http module)
  • Interceptors: Global request/response transformation pipeline
  • Automatic transforms: JSON parsing, URL encoding, form data conversion
  • Error handling: Structured error objects with response, request, and config
  • Cancellation: AbortController support for request cancellation
  • Progress tracking: Upload/download progress events for file handling

FAQ

Why use Axios instead of the Fetch API?
Axios provides automatic JSON transformation, request/response interceptors, timeout handling, progress tracking, and error objects with response data. The Fetch API requires manual JSON parsing and lacks interceptors and timeouts.
How do I cancel requests in Axios?
Use AbortController (Axios v0.22+). Pass { signal: controller.signal } in the config and call controller.abort() to cancel. This replaces the deprecated CancelToken API.
Is Axios tree-shakeable?
No. Axios is not tree-shakeable because it is a single monolithic instance. For smaller bundles, consider using the Fetch API or ky for specific use cases.