npmaxiosv1.14.0
npmAdvanced

axios

Promise based HTTP client for the browser and node.js

httpapi-clientinterceptorspromiseisomorphicxhrajaxnodebrowserfetch
The Problem

The native fetch API is verbose for the patterns every app uses: you need to manually check response.ok, call response.json(), set Content-Type headers on every POST, and handle errors yourself. Axios wraps fetch with sensible defaults and adds features like request/response interceptors that are hard to implement cleanly with fetch.

Mental Model

Axios is a promise-based HTTP client that treats requests as a pipeline: request interceptors run before the request is sent, the request goes out, then response interceptors run on the way back. This makes cross-cutting concerns like auth tokens and error logging trivially easy to add in one place.

60-second start

Install axios

npm install axios
import { } from 'axios';

Use it when

Use axios when you need request/response interceptors (auth headers, logging, retry logic), want automatic JSON serialisation/deserialisation, need to cancel in-flight requests, or want consistent behaviour between browser and Node.js environments.

Skip it when

For simple requests in modern apps, fetch is built-in and perfectly adequate. For lightweight browser-only code, ky is a smaller alternative. React Query or SWR abstract data fetching further โ€” prefer those when you also need caching and state management.

Alternatives
kyTiny fetch wrapper for browser-only use โ€” same idea as axios but ~2KB instead of ~13KB
fetchBuilt into browsers and Node 18+ โ€” no install needed for simple use cases
react-queryCombines data fetching with caching and state โ€” the right abstraction for React apps that need server state

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.