1.5.3 • Published 1 year ago

undici-shim v1.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

undici-shim Codacy Badge GitHub repo size

A small ESM/UMD library providing the fast request function from Undici within Node, otherwise window.fetch is utilized when running in a browser environment.

Why?

Upon trying to distribute a project, I found Undici could not be used on the client-side. As such, this is a drop-in replacement for Undici when using bundlers like webpack/rollup.

Without the overhead of WHATWG Streams, the request method proves much faster than fetch in both latency and throughput.

TestsSamplesResultsToleranceDifference with slowest
undici - fetch201028.31 req/sec± 2.71 %-
http - no keepalive103891.51 req/sec± 2.00 %+ 278.44 %
undici - pipeline956034.47 req/sec± 2.95 %+ 486.83 %
http - keepalive506382.57 req/sec± 2.98 %+ 520.68 %
undici - request158528.35 req/sec± 2.11 %+ 729.35 %

Install

npm i undici-shim

Usage

ESM

import request from 'undici-shim'
const res = await request('https://jsonplaceholder.typicode.com/posts/1')

console.log(await res.body.json())

You can also use Undici fetch instead of request for consistency across environments.

import { fetch } from 'undici-shim'
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1')

console.log(await res.json())

CommonJS

const { fetch } = require('undici-shim')

fetch('https://jsonplaceholder.typicode.com/posts/1')
    .then(res => res.json())
    .then(console.log)

Named Exports

Node Starting from v1.3.2, named exports are identical to Undici.

import { request, Dispatcher, Headers, ... } = from 'undici-shim'

Browser

import { fetch, Request, Response, Headers } = from 'undici-shim'
1.5.3

1 year ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.0.0

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago