Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt

Use this file to discover all available pages before exploring further.

undici is a high-performance HTTP/1.1 client built specifically for Node.js. It powers the native fetch() implementation in Node.js v18+ and provides advanced APIs for connection pooling, pipelining, proxying, mocking, and more — giving you full control over your HTTP stack.

Quickstart

Get up and running with your first HTTP request in minutes

undici vs. fetch

Understand when to use the undici module vs. Node.js built-in fetch

API Reference

Explore all public APIs: request, fetch, dispatchers, and more

Guides

Proxy setup, mocking, caching, WebSocket, and testing guides

Why undici?

undici delivers exceptional HTTP performance through a purpose-built architecture that eliminates the overhead of Node.js’s built-in http module. Benchmarks show undici.request() achieving over 18,000 req/sec — more than 3x faster than alternatives like axios or request.

Connection Pooling

Efficient persistent connections with configurable pool sizes

HTTP Pipelining

Send multiple requests over a single connection for maximum throughput

Interceptors

Compose caching, retry, redirect, and DNS interceptors declaratively

Proxy Support

HTTP, HTTPS, SOCKS5, and environment-based proxy configuration

Mocking

Intercept and mock HTTP requests for testing without real servers

Web APIs

WebSocket, EventSource, CacheStorage, and Cookies support

Get started

1

Install undici

Add undici to your Node.js project:
npm install undici
2

Make your first request

Use the request API for maximum performance:
import { request } from 'undici'

const { statusCode, headers, body } = await request('https://api.example.com/data')
const data = await body.json()
console.log(statusCode, data)
3

Configure a dispatcher

Use an Agent for connection pooling across requests:
import { Agent, setGlobalDispatcher, request } from 'undici'

const agent = new Agent({ keepAliveTimeout: 10_000, connections: 10 })
setGlobalDispatcher(agent)

// All subsequent requests share the pooled connections
const { body } = await request('https://api.example.com/users')
const users = await body.json()
4

Explore advanced features

Add interceptors for caching, retries, and more:
import { Agent, interceptors, cacheStores } from 'undici'

const agent = new Agent().compose(
  interceptors.cache({
    store: new cacheStores.MemoryCacheStore()
  }),
  interceptors.retry({ maxRetries: 3 })
)

Performance comparison

undici consistently outperforms other HTTP clients in Node.js benchmarks:
ClientRequests/secvs. slowest
axios5,708baseline
node-fetch5,945+4%
undici fetch5,903+3%
undici stream18,245+220%
undici request18,340+221%
undici dispatch22,234+289%
Benchmarks run with 50 TCP connections and pipelining depth of 10 on Node.js 22.11.0. Results will vary by workload.

Build docs developers (and LLMs) love