Back to articles
Undici Has a Free API — Here's How to Use Node.js's Fastest HTTP Client

Undici Has a Free API — Here's How to Use Node.js's Fastest HTTP Client

via Dev.to WebdevAlex Spinov

Undici is the HTTP/1.1 client that powers Node.js's built-in fetch. It is significantly faster than the legacy http module and provides connection pooling, interceptors, and streaming. Installation npm install undici Note: Undici is bundled with Node.js 18+ as the engine behind globalThis.fetch . Basic Requests import { request } from " undici " ; // Simple GET const { statusCode , headers , body } = await request ( " https://api.github.com/users/nodejs " , { headers : { " User-Agent " : " undici-example " } }); const data = await body . json (); console . log ( ` ${ data . login } : ${ data . public_repos } repos` ); Connection Pooling import { Pool } from " undici " ; // Create a pool with 10 connections const pool = new Pool ( " https://api.example.com " , { connections : 10 , pipelining : 1 }); // Make concurrent requests through the pool const results = await Promise . all ( Array . from ({ length : 100 }, ( _ , i ) => pool . request ({ path : `/items/ ${ i } ` , method : " GET "

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles