How it works · HTTP client for JavaScript

How Axios works

One way to make web requests that works the same in a browser and in Node, with hooks before and after every request.

Think of it like this. A mailroom: your letter passes a row of clerks on the way out, a courier carries it, and the reply passes another row of clerks on the way back.

  1. The instance What you import: a function with your defaults attached. lib/axios.js
  2. Interceptors Your functions that see every request before it leaves and every response before you do. lib/core/InterceptorManager.js
  3. The request Merges your settings with the defaults and lines everything up into one chain. lib/core/Axios.js
  4. Dispatch Turns your data into what goes on the wire, and the reply back into data. lib/core/dispatchRequest.js
  5. Adapters The part that really sends it: one for browsers, one for Node, one for fetch. lib/adapters

Follow one thing through: axios.post("/orders", { tea: 1 })

  1. Your settings are merged over the defaults.lib/core/Axios.js
  2. A chain is built: request interceptors, then the real send, then response interceptors.lib/core/Axios.js
  3. The object is turned into JSON text, and the content type is set for you.lib/defaults/index.js
  4. An adapter is chosen: the first one that works where the code is running.lib/adapters/adapters.js
  5. The reply’s status is checked. By default anything outside 200 to 299 becomes an error.lib/core/settle.js
  6. The reply’s text is parsed back into an object.lib/core/dispatchRequest.js

The clever bit: The whole request is one chain of promises

Axios puts everything in one list: your request interceptors, then the function that sends, then your response interceptors. Then it walks the list with promise = promise.then(chain[i++], chain[i++]). Each step gets what the last one returned, and an error anywhere skips ahead to the next error handler. That one loop is why an interceptor can change a request, retry it, or refresh a login without the rest of your code knowing.

lib/core/Axios.js

Words you’ll meet

interceptor
A function that runs on every request or every response.
adapter
The code that actually talks to the network in one environment.
config
The settings for one request: address, method, headers, data.
transform
A function that changes the data on its way out or in.

Good questions to ask next

Open Axios in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take Axios apart yourself.

Free and open source. Nothing to install, no account.

More projects, taken apart

How React worksYou describe what the screen should look like. React works out the smallest set of changes to make it so.How Express worksA request comes in and passes through a list of functions, in order, until one of them answers.How Flask worksYou write a function for each address. Flask finds the right one for a request, calls it, and turns what it…How Redis worksOne big dictionary held in memory, answered by a single loop that takes one command at a time.How nanoGPT worksText becomes numbers, a model learns to guess the next number, and guessing again and again writes new text.How micrograd worksEvery number remembers how it was made, so the answer can be traced back to say how much each input mattered.How SQLite worksYour SQL is compiled into a small program, and a tiny virtual machine runs it against one file on disk.How FastAPI worksYou write a function with type hints. FastAPI reads the hints to check the request, convert the values and…How Vue worksVue notices which data each part of the screen reads, so when that data changes it knows exactly what to…How Requests worksOne friendly line, requests.get(url), on top of the fiddly work of opening connections and speaking HTTP.How Redux worksAll of an app’s state lives in one place, and the only way to change it is to describe what happened.How Git worksEvery version of every file is stored under a name made from its own contents, and a commit is a small note…How Preact worksThe same idea as React, in a few kilobytes: you describe the screen, and Preact changes only what is…How Zustand worksA store is a value, a way to change it, and a list of who wants to know. The whole core is about a hundred…How htmx worksAny element can ask the server for a piece of HTML and put it into the page. You write attributes, not…How LevelDB worksA store for keys and values that makes writing fast by never changing a file: it only adds, and tidies up…How etcd’s Raft worksSeveral servers keep the same list of changes in the same order, even when some of them crash. This is the…

Written by hand from the code as it was on 2026-12-04 (commit 1ac7a18). Axios belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.