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.
- 📦 The instance What you import: a function with your defaults attached. lib/axios.js
- 🚇 Interceptors Your functions that see every request before it leaves and every response before you do. lib/core/InterceptorManager.js
- 🎛️ The request Merges your settings with the defaults and lines everything up into one chain. lib/core/Axios.js
- 📤 Dispatch Turns your data into what goes on the wire, and the reply back into data. lib/core/dispatchRequest.js
- 🚚 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 })
- Your settings are merged over the defaults.lib/core/Axios.js
- A chain is built: request interceptors, then the real send, then response interceptors.lib/core/Axios.js
- The object is turned into JSON text, and the content type is set for you.lib/defaults/index.js
- An adapter is chosen: the first one that works where the code is running.lib/adapters/adapters.js
- The reply’s status is checked. By default anything outside 200 to 299 becomes an error.lib/core/settle.js
- 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.
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
- In what order do request interceptors run?
- How does Axios decide a response is an error?
- How does cancelling a request work?
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
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.