Axios vs Fetch API
Axios vs the Fetch API compared for 2026: Axios 1.21 (the long-running promise-based HTTP client with interceptors, adapters and a Node.js transport) vs native fetch() in browsers and Node.js. Includes how each handles 404s, bad JSON, JSON bodies, redirects, timeouts against a slow server, decompression bombs, request speed, bundle size and the 2026 supply-chain incident.
Quick Answer
Axios and fetch() both make HTTP requests from JavaScript and return promises, but they disagree on almost every default. fetch() is built into every modern browser and has been stable in Node.js since v21; it resolves on any HTTP status, gives you a Response you parse yourself and has no timeout option, so you pass an AbortSignal. Axios 1.21.1 (9 November 2026) is a library on top of XHR, Node's http module or fetch: it rejects non-2xx responses, serializes objects to JSON, parses JSON for you, offers interceptors, instances with a baseURL, maxContentLength and maxRedirects, and redaction of secrets in error logs. In our Node.js 22.23.5 runs on 30 November 2026, fetch handled 2,237-2,615 sequential requests per second against 1,894-1,990 for Axios, adds 0 bytes to a bundle against 22.3 kB gzipped, and an AbortSignal.timeout(5000) stopped a server dripping one byte per second at 5.0 s, while Axios's default Node adapter with timeout: 5000 kept reading for the full 25 s. Axios caught problems fetch leaves to you: a 200 MB decompression bomb stopped at 10 MB with maxContentLength in under 50 ms (fetch buffered all 200 MB at 683 MB RSS), and a 404 became an error without extra code.
Last updated November 30, 2026. Covers Axios 1.21.1 (9 November 2026) and the Fetch API in Node.js 22.23.5; npm registry metadata, the Axios changelog, README, release notes and adapter source, Node.js and undici docs and MDN read on 30 November 2026, plus behaviour, timeout, size-limit, speed and bundle runs we did that day.
| Feature | Axios | Fetch API |
|---|---|---|
| Licence & Source | MIT; axios/axios, ~109.4k stars | Web standard (WHATWG Fetch); Node.js implementation in undici (MIT) |
| Version (Nov 2026) | 1.21.1 on 9 Nov 2026 (0.x: 0.35.0 on 3 Nov 2026) | Part of the runtime; stable in Node.js since v21.0.0 (we tested 22.23.5) |
| Where It Runs | Browsers (XHR or fetch), Node.js (http), Deno, Bun; any runtime with fetch | All modern browsers, Node.js 18+, Deno, Bun, Workers and other edge runtimes |
| Install & Dependencies | 4 deps; 27 packages, 4.4 MB in our install | Nothing to install |
| Our Run: Browser Bundle (min / gzip) | 58,800 B / 22,298 B (instance + interceptor + get) | 209 B / 203 B (our wrapper with ok check and timeout) |
| HTTP 404 / 500 Responses | Rejects non-2xx (validateStatus); 404 → ERR_BAD_REQUEST | Resolves with ok=false; you check response.ok / status |
| Sending a JSON Body | Object → JSON string, Content-Type application/json | Manual JSON.stringify + Content-Type header; object body sent as [object Object] |
| Invalid JSON in the Response | Returned as raw string by default; throws only with responseType 'json' + silentJSONParsing false | response.json() throws SyntaxError |
| Timeout Option | timeout (ms), default 0 = none; also AbortController signal | No option; signal: AbortSignal.timeout(ms) or AbortController |
| Our Run: 1 byte/s Server, 5 s Timeout | http adapter: not aborted, 25 bytes after 25.0 s; fetch adapter: ETIMEDOUT at 5.0 s | AbortSignal.timeout(5000): TimeoutError at 5.0 s |
| Redirect Limit (Node.js) | Follows up to 21 (maxRedirects); 22 → ERR_FR_TOO_MANY_REDIRECTS | Follows up to 20; 21 → TypeError 'fetch failed' (cause: redirect count exceeded) |
| Response Size Limit | maxContentLength / maxBodyLength, default -1 (unlimited) | None built in; stream and count bytes yourself |
| Interceptors / Middleware | Request and response interceptors per instance | None; wrap fetch in a function |
| Query Arrays | params {ids:[1,2]} → ids[]=1&ids[]=2 (bracket style) | URLSearchParams append → ids=1&ids=2 (repeat style) |
| Upload / Download Progress | onUploadProgress / onDownloadProgress | Download via reading response.body; no upload progress events |
| Secrets in Error Logs | error.toJSON() includes config headers; redact option masks keys | Errors carry no request config; nothing to redact |
| Security Releases in 2026 | 10 releases with Security Fixes sections; 1.14.1 and 0.30.4 removed from npm | Patched with the runtime (Node.js / browser releases) |
| Our Run: 5,000 Sequential GETs | 1,894-1,990 req/s, 2.14-2.25 s CPU (fetch adapter: 1,346-1,470) | 2,237-2,615 req/s, 1.62-1.79 s CPU |
| Our Run: 1,000 x 100 ms at 100 In Flight | 1,122-1,159 ms, 0.48-0.60 s CPU | 1,123-1,139 ms, 0.28-0.38 s CPU |
| Our Run: Node.js Load Time | import 74-93 ms, require 49-66 ms | Global, nothing to load |
Axios
Axios is a promise-based HTTP client for browsers and Node.js. One API sits on top of three adapters: XMLHttpRequest in browsers, Node's http/https modules on the server, and fetch where you choose it (adapter: 'fetch') or where nothing else exists. You get axios.create() instances with a baseURL, default headers and a timeout, request and response interceptors, automatic JSON serialization of objects, JSON parsing of responses, rejection of non-2xx statuses through validateStatus, params serialization, upload and download progress events, maxContentLength and maxBodyLength limits, a 21-redirect default in Node.js, proxy support from environment variables, and AxiosError objects with a code, the config and the response. Version 1.21.0 (October 2026) added response.duration, and the redact option masks keys such as authorization when an error is serialized with toJSON(). The 1.x line is MIT-licensed, ships TypeScript types, carries npm provenance attestations, and the old 0.x line still gets releases (0.35.0 on 3 November 2026).
Pros
- Rejects 4xx/5xx responses by default (our 404 became AxiosError ERR_BAD_REQUEST), so error handling lives in one catch block
- Sends objects as JSON with Content-Type: application/json and parses JSON responses without extra code
- maxContentLength stopped a 200 MB gzip bomb after 10 MB in 47-50 ms at 73 MB RSS; fetch buffered all 200 MB at 683 MB
- Interceptors, instances with baseURL and defaults, params serialization and progress events built in
- redact: ['authorization'] masks secrets in error.toJSON(), which otherwise contains the Authorization header
- Same API in browsers, Node.js, Deno and Bun (smoke-tested in CI since 1.15.0), with response.duration since 1.21.0
Cons
- Adds 22.3 kB gzipped (58.8 kB minified) to a browser bundle in our build, and 27 packages / 4.4 MB to node_modules
- No timeout by default; in Node its timeout is a socket inactivity timer, so a server sending 1 byte per second ran 25 s past a 5,000 ms timeout
- Slower and heavier per request in our runs: 1,894-1,990 sequential req/s at 2.14-2.25 s CPU against fetch's 2,237-2,615 at 1.62-1.79 s
- Invalid JSON is returned silently as a string unless you set responseType: 'json' and transitional.silentJSONParsing: false
- A dependency on the supply chain: ten 2026 releases carry security fixes, and two versions published on 31 March 2026 were pulled from npm
Best For
Apps that make many API calls through shared configuration (auth headers, base URLs, retries, logging), Node.js services that need response size limits and redirect control without writing them, and teams that want one HTTP API across browser and server.
Fetch API
fetch() is the standard web API for HTTP requests, built into every modern browser, Deno, Bun, Cloudflare Workers and Node.js. In Node.js it was added in v17.5.0, unflagged in v18.0.0 and marked stable in v21.0.0; the implementation is undici, and you can pass a custom undici dispatcher for connection pooling, proxies or timeouts. fetch() returns a promise for a Response: the promise rejects only on network failure, an aborted signal or a bad request, not on HTTP 404 or 500, so you check response.ok yourself. Bodies are streams you read once with json(), text(), arrayBuffer() or by iterating response.body. Cancellation and timeouts use AbortController and AbortSignal.timeout(); redirects follow the spec (up to 20, or redirect: 'manual' / 'error'); there are no interceptors, base URLs, size limits or JSON serialization of request bodies. Nothing to install, nothing to update except the runtime.
Pros
- Zero install and zero bundle cost: our equivalent wrapper was 203 bytes gzipped against 22.3 kB for Axios
- Fastest in our Node runs: 2,237-2,615 sequential req/s at 1.62-1.79 s CPU, and the lowest CPU at 100 requests in flight (0.28-0.38 s)
- AbortSignal.timeout() is a true deadline: it aborted a slow-drip response at 5.0 s where Axios's Node adapter did not
- A web standard: the same code runs in browsers, Node.js, Deno, Bun, edge runtimes and service workers
- Streams response bodies natively (response.body is a ReadableStream), and redirect: 'manual' exposes 3xx responses
- No third-party package in your supply chain; patches arrive with the runtime
Cons
- A 404 or 500 resolves normally; forget the response.ok check and error pages flow into your app as data
- Passing an object as body sent the literal string [object Object] as text/plain; you must JSON.stringify and set Content-Type yourself
- No response size limit: a 200 MB decompression bomb was fully buffered by arrayBuffer() at 683-684 MB RSS
- No timeout by default in Node: a server that never answered was still pending after 20 s (undici's own header timeout is 300 s)
- No interceptors, base URL, query-array serialization or progress events; you write a wrapper or add a library
Best For
Frontends and edge functions where bundle size matters, libraries that should not pull in dependencies, simple API calls, and teams willing to keep a small wrapper that checks response.ok, sets JSON headers and adds a timeout.
Two contracts: a standard primitive versus a configured client
fetch() was designed as a low-level primitive. It resolves as soon as headers arrive with a Response object, whatever the status, and leaves everything above the transport to you: status checks, body parsing, serialization, retries, timeouts. Axios was designed as an application client. It resolves with data already parsed, rejects anything outside 200-299, and carries a config object through interceptors, transforms and an adapter. We ran both on Node.js 22.23.5 against a local test server, and the defaults diverged on every case we tried. A 404 resolved in fetch with ok=false and status 404; Axios rejected with AxiosError ERR_BAD_REQUEST. Posting the object {a: 1} with fetch sent the body [object Object] with Content-Type text/plain;charset=UTF-8, and even a JSON.stringify body went out as text/plain until we set the header; Axios sent {"a":1} as application/json. A truncated JSON body made response.json() throw SyntaxError, while Axios handed back the raw string '{"oops": ' as response.data with no error. Its README explains why: forcedJSONParsing silently falls back to the string unless you set responseType: 'json' and transitional.silentJSONParsing: false, which made it reject with ERR_BAD_RESPONSE. Query arrays differ too: Axios serialized {ids: [1, 2]} as ids[]=1&ids[]=2, URLSearchParams as ids=1&ids=2. None of this is a bug on either side, but it is exactly what breaks when a team moves code from one to the other.
Timeouts and slow servers: where the defaults bite
Neither option times out by default. Against an endpoint that accepted the connection and never answered, a plain axios.get() and a plain fetch() were both still pending after 20 seconds. Axios documents timeout as defaulting to 0, meaning none, and its README now carries a note telling you to set one in production. Node's fetch inherits undici's limits, which wait 300 seconds for headers and 300 seconds between body chunks. With explicit settings both behaved on a hung server: fetch with AbortSignal.timeout(2000) rejected with TimeoutError after 2,004 ms, Axios with timeout: 2000 rejected after 2,004 ms with ECONNABORTED, and Axios's fetch adapter with ETIMEDOUT (the README confirms the code differs by adapter unless you set transitional.clarifyTimeoutError). The difference showed up with a server that sends one byte per second for 25 seconds. AbortSignal.timeout(5000) aborted at 5,003 ms. Axios's fetch adapter with timeout: 5000 aborted at 5,007 ms. Axios's default Node adapter with timeout: 5000 never fired and returned all 25 bytes after 25.0 seconds. The source shows why: in Node it calls ClientRequest#setTimeout, which measures socket inactivity, and each byte resets it. That is fine for most APIs, but a slow-loris upstream can hold an Axios request open indefinitely. If you need a hard deadline in Node.js, pass signal: AbortSignal.timeout(ms) to Axios as well, or select adapter: 'fetch'.
What we measured: speed, CPU, bundle size and load time
We ran the server pinned to one core and the client to the other on a 2-vCPU sandbox, three runs each, with keep-alive on (Node's default). 5,000 sequential GETs of a small JSON document after a 300-request warm-up: fetch managed 2,237-2,615 requests per second using 1.62-1.79 s of CPU, Axios with its default http adapter 1,894-1,990 at 2.14-2.25 s, and Axios on its fetch adapter 1,346-1,470 at 2.94-3.17 s, since it adds its own pipeline on top of fetch. With 1,000 requests to an endpoint that waits 100 ms, 100 in flight, all three finished in about 1.1-1.3 s because the wait dominates, but CPU still differed: 0.28-0.38 s for fetch, 0.48-0.60 s for Axios and 0.41-0.51 s for its fetch adapter. In Node, import('axios') took 74-93 ms and require('axios') 49-66 ms; fetch is a global. For the browser we bundled the same small client with esbuild 0.25.12, minified: an Axios instance with a baseURL, timeout, one request interceptor and a GET came to 58,800 bytes, 22,298 gzipped. The fetch version, with an ok check, an Authorization header and AbortSignal.timeout, was 209 bytes, 203 gzipped. An npm install of axios 1.21.1 on a cold cache pulled 27 packages (form-data, follow-redirects, proxy-from-env, https-proxy-agent and their dependencies) totalling 4.4 MB in 1.5 s. For most apps the network dwarfs these numbers; on edge functions, cold starts and mobile bundles they do not.
Safety limits: decompression bombs, redirects and leaked tokens
Server code that calls hosts it does not control needs limits, and here Axios gives you more out of the box. We served a 203,860-byte gzip body that expands to 200 MB. fetch().arrayBuffer() decompressed and buffered all 209,715,200 bytes in 0.9-1.0 s with peak RSS of 683-684 MB; fetch has no size option, so the defence is to read response.body as a stream and stop counting at a limit. Axios by default did the same, 600 ms and 470 MB, because maxContentLength defaults to -1; its README now warns about exactly this attack. With maxContentLength: 10 MB it rejected with ERR_BAD_RESPONSE after 47-50 ms at 73 MB RSS, and the fetch adapter enforced it too (67-75 ms, 83-84 MB). Redirects: Node's fetch followed 20 hops and failed on the 21st with TypeError 'fetch failed', cause 'redirect count exceeded'; Axios followed 21 and failed on the 22nd with ERR_FR_TOO_MANY_REDIRECTS. With maxRedirects: 0 Axios rejected the 302 with ERR_BAD_RESPONSE, while fetch with redirect: 'manual' returned the 302 and its Location header. Logging is the quiet risk. We sent Authorization: Bearer SECRET123 to a 404 and serialized the Axios error: both error.toJSON() and JSON.stringify(error) contained the token, because the error carries the request config. With redact: ['authorization'], toJSON() printed [REDACTED ****] and JSON.stringify no longer contained it, though error.config itself still holds the real header. fetch errors carry no request config at all.
Supply chain, maintenance and when not to use each
Axios is maintained and moves quickly: npm shows 17 available 1.x releases in 2026 up to 1.21.1 on 9 November, and ten of them carry a Security Fixes section in the changelog or release notes, from CRLF header injection and no_proxy SSRF in 1.15.0 to a follow-redirects floor raised for CVE-2026-116689 in 1.21.1. The registry also lists 1.14.1 and 0.30.4 as published on 31 March 2026 and no longer available; security vendors including Snyk and Datadog Security Labs reported them as a hijacked-maintainer supply-chain compromise. Axios 1.15.0, a week later, moved publishing to npm OIDC trusted publishing, and 1.21.1 carries an SLSA provenance attestation. The lesson applies to any dependency: pin with a lockfile, review updates and run npm audit signatures. fetch has none of this surface, since it updates with your browser or Node.js. Do not choose Axios for a library or SDK you publish, for edge functions with tight size budgets, or when all you do is a few GETs; the 22 kB and 27 packages buy you nothing there. Do not rely on its Node timeout as a deadline. Do not choose bare fetch for server code that downloads from untrusted URLs unless you add a streaming size cap, or for large apps without a shared wrapper; teams end up with fifty slightly different ok checks. Migrating from Axios to fetch means replacing interceptors with a wrapper, adding JSON headers, moving params to URLSearchParams (watch the ids[] style) and handling non-2xx explicitly. Lighter wrappers such as ky sit between the two.
Verdict
Use fetch() by default in new browser, edge and library code, and wrap it once. The wrapper is a dozen lines: check response.ok and throw, JSON.stringify request bodies with a Content-Type header, and pass signal: AbortSignal.timeout(ms) so a stalled server cannot hold a request open. That gets you the fastest and cheapest option we measured (2,237-2,615 sequential req/s, 0 bytes added to the bundle) and removes a third-party package from your supply chain. Choose Axios when your code makes many calls through shared configuration and you would otherwise rebuild it: interceptors for auth refresh and logging, instances with a baseURL, bracket-style params, upload progress, and, above all on Node.js servers that call untrusted or flaky hosts, maxContentLength and maxRedirects, which stopped a 200 MB decompression bomb at 10 MB where fetch buffered all of it. If you use Axios, set three things on every instance: a timeout, a maxContentLength, and redact: ['authorization', 'cookie'] so error logs do not leak tokens. In Node.js remember that Axios's timeout is an inactivity timer: for a hard deadline add signal: AbortSignal.timeout(ms) or use adapter: 'fetch'. Pin versions and verify provenance either way.