talira

Promise based HTTP client for the browser and node.js

open sourceMITself-hostablefree

axios is a promise-based HTTP client for JavaScript with one API in browsers (XMLHttpRequest or fetch) and in Node.js (its http module). It adds interceptors for requests and responses, request and response transforms, automatic JSON handling, cancellation, multipart and URL-encoded form serialization, upload and download progress, and client-side XSRF protection. Adapters decide how requests are sent (xhr, http, or fetch since 1.7.0) and can be replaced with your own, which also helps in tests. It includes TypeScript definitions and installs with npm, yarn, pnpm, Bun or Deno.

Problems it solves

  • make HTTP requests from the browser and from Node.js with the same code
  • add an auth token header to every API request in one place
  • log or modify every request and response my frontend sends to the backend
  • cancel an in-flight request when the user navigates away or types again
  • show an upload progress bar while sending a big file from the browser
  • send multipart file uploads or form data from JavaScript without building the body by hand
  • set a timeout on HTTP calls so a slow API doesn't hang my app
  • I want HTTP error status codes to throw instead of checking response.ok every time
  • create a preconfigured API client with a base URL and default headers
  • limit upload or download speed in a Node.js script
  • send an XSRF token header with browser requests to guard against cross-site request forgery
  • stub out network calls in tests by swapping how requests are sent

Features

  • XMLHttpRequest and fetch in browsers, http module in Node.js
  • Promise API with async/await
  • request and response interceptors
  • request and response data transforms
  • cancellation with AbortController
  • automatic JSON serialization and parsing
  • multipart/form-data and URL-encoded serialization
  • upload and download progress events
  • upload and download rate limits in Node.js
  • client-side XSRF protection
View 4 more
  • replaceable adapters (xhr, http, fetch, or your own)
  • instances with base URL, headers and timeouts
  • experimental HTTP/2 in the Node.js adapter
  • TypeScript definitions and an isAxiosError type guard

Limitations

  • HTTP/2 support is experimental: only the Node.js http adapter has it, and behaviour depends on the runtime and Node.js version1

Capabilities

Has an APIplan not known

Alternatives

The same job

These do what axios does.

  1. Got Human-friendly and powerful HTTP request library for Node.js
  2. SuperAgent Ajax for Node.js and browsers (JS HTTP client)
  3. Ky Tiny & elegant JavaScript HTTP client based on the Fetch API
  4. ofetch A better fetch API. Works on node, browser, and workers.
  5. node-fetch A light-weight module that brings the Fetch API to Node.js
  6. undici An HTTP/1.1 client, written from scratch for Node.js

Compare axios with the top 3