axios
Promise-based HTTP client for the browser and Node.js — interceptors, automatic JSON parsing, request cancellation, and progress events.
axios
General JSPromise-based HTTP client for the browser and Node.js — interceptors, automatic JSON parsing, request cancellation, and progress events.
Fit
Bundle (gzip)
18.1 kB
47.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
The native fetch API lacks request/response interceptors, automatic JSON serialization, request timeout support, and meaningful error objects that include the response body when a request fails.
What It Does
Axios provides a simple API for HTTP requests with automatic JSON request/response transformation, configurable interceptors for auth headers and error handling, request cancellation via AbortController, upload/download progress callbacks, and detailed error objects including HTTP status and response body.
Installation
npm install axiosUsage Example
import axios from 'axios';
// Create a configured instance
const api = axios.create({
baseURL: process.env.API_URL,
timeout: 10000,
});
// Add auth interceptor
api.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${getToken()}`;
return config;
});
// Type-safe response
const { data } = await api.get<{ users: User[] }>('/users');
const user = await api.post<User>('/users', { name: 'Alice', email: 'alice@example.com' });Related packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.