Guide
axios Alternatives 2026: got, ky, and undici



axios was compromised in a supply chain attack in March 2026. Compare got, ky, undici, and native fetch — performance, bundle size, and TypeScript support.
Contents
Contents
TL;DR
Axios maintainers identified versions 1.14.1 and 0.30.4 as affected by the March 2026 npm compromise. Check the installed package against the maintainer report. Use Got for Node.js services that need hooks, ky for Fetch-based code, or installed Undici for connection pooling and lower-level APIs. Use native Fetch for basic requests without a separate client package.
Key Takeaways
- Compromised versions. Check the lockfile for the affected versions listed above and review current Axios advisories before choosing a release.
- got is a Node.js client with ESM, bundled TypeScript types, retries, and hooks.
- ky wraps Fetch with JSON helpers and request hooks. Check the Node.js requirement for the version you install.
- undici powers Node.js's built-in
fetch. Install the package when you need control over connection pooling or want to use lower-level APIs such asrequest(). Undici and built-in Fetch - Native Fetch is available without a separate package on supported Node.js releases.
The March 2026 axios Supply Chain Attack
At 00:21 UTC on March 31, 2026, an attacker who had compromised the npm credentials of axios lead maintainer jasonsaayman published two backdoored releases simultaneously:
- axios@1.14.1 — pushed as the
latesttag, affecting anyone runningnpm install axiosor automated dependency updates - axios@0.30.4 — pushed as the
legacytag, targeting projects on the older 0.x branch
The malicious packages introduced a hidden dependency called plain-crypto-js, which contained an obfuscated postinstall script. The script executed immediately on installation — before any application code ran — and deployed WAVESHAPER.V2, a cross-platform backdoor attributed to UNC1069, a financially motivated North Korean threat actor active since at least 2018.
npm removed the compromised packages at 03:25 UTC, three hours after they appeared. Elastic Security Labs, Datadog Security Labs, and Google's GTIG published detailed analyses confirming the attribution and payload behavior. The WAVESHAPER.V2 backdoor exfiltrates cloud access keys, database passwords, and API tokens, and installs a persistent Remote Access Trojan on Windows, macOS, and Linux.
What this means for your project:
- If your lockfile pins
axios@1.14.1oraxios@0.30.4, treat any system that rannpm installbetween March 31 00:21 and 03:25 UTC as fully compromised. - If your lockfile pins
axios@1.14.0or earlier, you were not affected by this specific incident. - Projects using got, ky, undici, or native fetch were not impacted.
The affected releases introduced an unexpected dependency. The Axios 1.22.0 npm manifest declares no package-level postinstall script.
Quick Comparison
| axios | got | ky | undici | native fetch | |
|---|---|---|---|---|---|
| Browser Support | ✅ | ❌ | ✅ | ❌ | ✅ |
| TypeScript | bundled | bundled | bundled | bundled | native |
| HTTP/2 | Experimental, opt-in in the Node.js HTTP adapter | Opt-in | Depends on the Fetch transport | 8.14.0 allows it by default when negotiated through ALPN | Depends on the runtime |
| Failed-request retry policy | Add a policy or plugin | Default for eligible failures | Default for eligible failures | Opt in with RetryAgent | Add an application policy |
| License | MIT | MIT | MIT | MIT | — |
got: The Feature-Complete Node.js Client
got is the go-to axios alternative when you need a rich feature set and are writing Node.js-only code. Version 14.x is ESM-first with full TypeScript definitions bundled — no @types/got required.
npm install got
import got from 'got';
// Basic GET with automatic JSON parsing
const data = await got('https://api.example.com/users').json();
// POST with JSON body — got handles Content-Type automatically
const result = await got.post('https://api.example.com/users', {
json: { name: 'Alice', email: 'alice@example.com' },
}).json();
// Retry on failure (default: 2 retries with exponential backoff)
const withRetry = await got('https://api.example.com/data', {
retry: {
limit: 3,
methods: ['GET'],
statusCodes: [429, 500, 502, 503],
},
}).json();
// Timeout configuration
const withTimeout = await got('https://api.example.com/slow', {
timeout: {
request: 5000, // 5s total
connect: 1000, // 1s to establish connection
response: 3000, // 3s for first byte
},
}).json();
got's killer feature is its hooks system, which replaces axios interceptors with a more composable pattern:
import got, { type Got } from 'got';
// Create a reusable instance (equivalent to axios.create())
const api: Got = got.extend({
prefixUrl: 'https://api.example.com',
headers: { 'Authorization': `Bearer ${process.env.API_TOKEN}` },
hooks: {
beforeRequest: [
(options) => {
console.log(`→ ${options.method} ${options.url}`);
},
],
afterResponse: [
(response) => {
console.log(`← ${response.statusCode} ${response.url}`);
return response;
},
],
beforeError: [
(error) => {
console.error(`Request failed: ${error.message}`);
return error;
},
],
},
});
// Use the instance — prefixUrl + relative path
const users = await api.get('users').json();
const user = await api.post('users', { json: { name: 'Bob' } }).json();
got also supports streaming natively, which is where it pulls ahead of axios for server-side use:
import got from 'got';
import { createWriteStream } from 'fs';
import { pipeline } from 'stream/promises';
// Stream a large response to disk without buffering the whole response
await pipeline(
got.stream('https://example.com/large-file.zip'),
createWriteStream('./output.zip'),
);
When to use got: Node.js-only services, complex APIs needing retries and hooks, streaming downloads/uploads, HTTP/2 endpoints, projects where you want a direct axios migration path.
ky: The Modern Fetch Wrapper
ky wraps Fetch with JSON helpers, retries, and hooks. The ky 2.2.0 package requires Node.js 22 or later for server-side use.
npm install ky@2.2.0
import ky from 'ky';
// GET with JSON — no .data wrapper, just the parsed object
const user = await ky.get('https://api.example.com/users/1').json();
// POST with automatic Content-Type: application/json
const created = await ky.post('https://api.example.com/users', {
json: { name: 'Alice' },
}).json();
// Built-in retry with exponential backoff
const resilient = await ky.get('https://api.example.com/flaky', {
retry: {
limit: 3,
methods: ['get', 'head'],
statusCodes: [429, 503],
backoffLimit: 3000,
},
}).json();
// Timeout (throws on expiry)
const timed = await ky.get('https://api.example.com/slow', {
timeout: 5000,
}).json();
ky's beforeRequest/afterResponse hooks work similarly to got's but are designed around the Fetch API's Request/Response objects:
import ky from 'ky';
const api = ky.create({
baseUrl: 'https://api.example.com/',
hooks: {
beforeRequest: [({ request }) => {
request.headers.set('X-Client', 'dashboard');
}],
afterResponse: [({ request, response }) => {
console.info(request.method, response.status);
}],
},
});
Use ky for Fetch-based browser code or shared request code when all target runtimes meet the package’s requirements. If a browser build budget drives the choice, compare outputs from your production build.
For a deeper ky vs. axios breakdown, see Axios vs ky in 2026.
Undici for Connection Pooling
Node.js bundles Undici for global fetch. Check process.versions.undici to see which version your Node.js process uses. The separately installed Undici 8.14.0 package requires Node.js 22.19.0 or later. That engine requirement applies to the npm install.
npm install undici@8.14.0
Use request() for the status code, headers, and a readable body directly. Use a Pool to control how connections to an origin are shared. Measure throughput with the response sizes and concurrency your service sees.
import { request } from 'undici';
// Read the status, headers, and body from request()
const { statusCode, headers, body } = await request(
'https://api.example.com/data',
{ method: 'GET' }
);
const data = await body.json();
// Connection pooling (default behavior — reuses TCP connections)
import { Pool } from 'undici';
const pool = new Pool('https://api.example.com', {
connections: 20,
pipelining: 4,
});
// Batch requests using the pool
const responses = await Promise.all([
pool.request({ path: '/users', method: 'GET' }),
pool.request({ path: '/products', method: 'GET' }),
pool.request({ path: '/orders', method: 'GET' }),
]);
In installed Undici 8.14.0, allowH2 defaults to true. The client uses HTTP/2 over TLS when ALPN negotiates it with the server. This example sets that option explicitly on a dispatcher. Check the version bundled with Node.js separately when you use global fetch.
import { Agent } from 'undici';
// Allow HTTP/2 when the client and server negotiate it
const agent = new Agent({ allowH2: true });
const { body } = await request('https://api.example.com/data', {
dispatcher: agent,
});
When to use Undici. Install it when your Node.js service needs explicit pooling, a configurable dispatcher, or lower-level response streaming.
For a focused undici vs got comparison, see got vs undici vs node-fetch (2026).
Native fetch: When Zero Dependencies Win
Node.js provides global fetch for requests such as reading JSON or sending a POST without adding an HTTP client dependency.
// Use the global fetch function in Node.js
const response = await fetch('https://api.example.com/users');
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const users = await response.json();
// POST with JSON
const created = await fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Alice' }),
});
The supply chain attack against axios highlighted what many developers had already observed: adding a third-party HTTP client means adding a trusted target for future attacks. For simple CRUD API consumption, native fetch eliminates that surface.
The tradeoffs are real: no built-in retries, no request hooks, no automatic JSON parsing of the request body, no timeout via setTimeout integration (use AbortController with signal), and verbose error handling. For anything beyond simple request/response, reach for ky or got.
When to use native fetch: Lambda functions and serverless environments where cold start matters, internal CLI tools, scripts where dependencies are a burden, projects that only need basic GET/POST without retry or timeout semantics.
Migration: From axios to Alternatives
axios → got (Node.js services)
// Before: axios
import axios from 'axios';
const client = axios.create({
baseURL: 'https://api.example.com',
headers: { Authorization: `Bearer ${token}` },
timeout: 5000,
});
const { data } = await client.get('/users');
const { data: created } = await client.post('/users', { name: 'Alice' });
// After: got
import got from 'got';
const client = got.extend({
prefixUrl: 'https://api.example.com',
headers: { Authorization: `Bearer ${token}` },
timeout: { request: 5000 },
});
const data = await client.get('users').json();
const created = await client.post('users', { json: { name: 'Alice' } }).json();
axios → ky (browser/isomorphic)
// Before: axios
import axios from 'axios';
const { data } = await axios.get('https://api.example.com/users');
const { data: created } = await axios.post(
'https://api.example.com/users',
{ name: 'Alice' }
);
// After: ky
import ky from 'ky';
const data = await ky.get('https://api.example.com/users').json();
const created = await ky.post('https://api.example.com/users', {
json: { name: 'Alice' },
}).json();
The key migration difference: axios wraps responses in a { data } envelope. Both got and ky call .json() directly on the response — there is no response.data wrapper.
Interceptors → Hooks
// Before: axios interceptors
client.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${getToken()}`;
return config;
});
client.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) logout();
return Promise.reject(error);
}
);
// After: got hooks (same pattern, different API)
const client = got.extend({
hooks: {
beforeRequest: [(options) => {
options.headers['Authorization'] = `Bearer ${getToken()}`;
}],
afterResponse: [(response) => {
if (response.statusCode === 401) logout();
return response;
}],
},
});
When to Use Which
Still on axios?
→ Check the installed version against the incident report and current advisories.
→ Keep Axios if its adapters and interceptors fit your application.
New project / migration?
→ Need browser support or edge runtime? → ky
→ Node.js only, complex needs (retries, hooks, streaming, HTTP/2)? → got
→ Need explicit connection pooling or low-level requests? → undici
→ Simple scripts, serverless, minimal dependencies? → native fetch
Browser-only React app?
→ ky or native fetch — axios's browser support is no longer a differentiator now that fetch is universal
Check the exact package and resolved dependencies in your lockfile when assessing an incident. Changing the HTTP client affects your application code and dependency tree.
When Axios Still Wins
The security incident is real and the advice to migrate is sound — but it would be dishonest to pretend axios has no genuine advantages. For teams that are not migrating immediately, understanding what axios does well clarifies what they would lose.
Axios interceptors are the most mature request/response middleware system in the JavaScript HTTP client ecosystem. The pattern of adding an interceptor to attach a bearer token, then another to refresh that token on 401 responses and retry the original request, has been implemented and debugged in production across thousands of codebases. got's hooks system covers the same use case but with a different API, and ky's afterResponse hooks require more careful implementation to avoid infinite retry loops on repeated 401s. The axios interceptor pattern is battle-tested and has extensive Stack Overflow documentation.
Request and response transformation — converting dates from ISO strings to Date objects on every response, normalizing API-specific error shapes, adding HMAC signatures to every outbound request body — is cleanly handled by axios transformers. The transformRequest and transformResponse arrays let you build a processing pipeline that applies globally across a client instance. This reduces boilerplate in individual API call sites. In got and ky, this same behavior requires hooks, which achieve the same result but with more explicit wiring.
The axios plugin ecosystem, while smaller than it once was, includes useful packages like axios-retry (automatic retry with exponential backoff), axios-cache-adapter (response caching with configurable TTLs), and axios-mock-adapter (test mocking). These packages are mature and well-tested. got has some equivalent functionality built-in (retries), and ky has retries built-in as well, but the adapter-based mocking ecosystem for testing is richer in axios.
Configure a shared API root with axios.create({ baseURL }), got.extend({ prefixUrl }), or ky.create({ baseUrl }). For example, with baseUrl: 'https://api.example.com/' on the ky instance, api.get('users') sends a GET request to https://api.example.com/users.
The Native Fetch Maturity Story
Node.js provides global Fetch with its bundled version of Undici. Read process.versions.undici to check that version before relying on an Undici feature.
What remains missing compared to axios or got: no automatic request body serialization. With axios and got, passing json: { name: 'Alice' } automatically sets Content-Type: application/json and serializes the body. With native fetch, you write JSON.stringify(body) and set the header manually. This is two lines instead of one option, but it is a friction point that ky and got eliminate.
Timeout handling with native fetch requires AbortController with AbortSignal.timeout(). Node.js 17.3+ ships this API, so for Node.js 20+ you write fetch(url, { signal: AbortSignal.timeout(5000) }). This is now ergonomic enough that it is not a meaningful disadvantage over axios's timeout option.
The edge runtime story is where native fetch has definitively won. Cloudflare Workers, Vercel Edge Functions, and Deno Deploy all implement the Fetch API specification. Code written with native fetch or ky (which wraps fetch) runs identically on these platforms. got and axios, which depend on Node.js's http module, do not. For teams building edge-deployed Next.js middleware or Cloudflare Workers, the choice of ky or native fetch is not optional — it is required by the runtime.
The missing piece for native fetch in production backend services is retry logic. Transient network failures, 503s from overloaded downstream services, and rate limit 429s all require retry with backoff. Implementing this on top of native fetch is straightforward but verbose. For backend services that make many outbound requests to third-party APIs, wrapping fetch with a simple retry function or reaching for ky (which has retry built-in) is the pragmatic choice.
View download trends for axios vs got vs undici on PkgPulse.