{"id":20256813,"url":"https://github.com/owen3h/undici-shim","last_synced_at":"2026-02-08T05:02:28.077Z","repository":{"id":178484328,"uuid":"655178513","full_name":"Owen3H/undici-shim","owner":"Owen3H","description":"Provides Undici request in Node, native fetch in the browser.","archived":false,"fork":false,"pushed_at":"2024-05-23T00:44:23.000Z","size":93,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-16T14:41:45.043Z","etag":null,"topics":["browser","fetch","http","node-fetch","request","shim","undici","webpack"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/undici-shim","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Owen3H.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-18T06:03:11.000Z","updated_at":"2024-05-23T00:44:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"51e14c96-620e-4073-876f-4ad838d2b687","html_url":"https://github.com/Owen3H/undici-shim","commit_stats":{"total_commits":60,"total_committers":3,"mean_commits":20.0,"dds":"0.15000000000000002","last_synced_commit":"d534780f8ff54a2102aeb157201c7328a2be92c5"},"previous_names":["owen3h/undici-shim"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen3H%2Fundici-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen3H%2Fundici-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen3H%2Fundici-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen3H%2Fundici-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Owen3H","download_url":"https://codeload.github.com/Owen3H/undici-shim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244207746,"owners_count":20416109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","fetch","http","node-fetch","request","shim","undici","webpack"],"created_at":"2024-11-14T10:48:26.834Z","updated_at":"2026-02-08T05:02:28.037Z","avatar_url":"https://github.com/Owen3H.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# undici-shim [![Codacy Badge](https://app.codacy.com/project/badge/Grade/22c825427e0a47cb80fffdc59b1684fd)](https://app.codacy.com/gh/Owen3H/undici-shim/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade) ![GitHub repo size](https://img.shields.io/github/repo-size/Owen3H/undici-shim)\n\n### A small ESM/UMD library providing the fast `request` function from [Undici](https://github.com/nodejs/undici) within Node, otherwise `window.fetch` is utilized when running in a browser environment.\n\n## Why?\nUpon trying to distribute a project, I found Undici could not be used on the client-side.\u003cbr\u003e\nAs such, this is a drop-in replacement for Undici when using bundlers like webpack/rollup.\u003cbr\u003e\n\nWithout the overhead of WHATWG Streams, the [request](https://undici.nodejs.org/#/?id=undicirequesturl-options-promise) method proves much faster than fetch in both latency and throughput.\n\n|        Tests        | Samples |      Results     | Tolerance | Difference with slowest |\n|---------------------|---------|------------------|-----------|-------------------------|\n| undici - fetch      |      20 |  1028.31 req/sec |  ± 2.71 % |                       - |\n| http - no keepalive |      10 |  3891.51 req/sec |  ± 2.00 % |              + 278.44 % |\n| undici - pipeline   |      95 |  6034.47 req/sec |  ± 2.95 % |              + 486.83 % |\n| http - keepalive    |      50 |  6382.57 req/sec |  ± 2.98 % |              + 520.68 % |\n| undici - request    |      15 |  8528.35 req/sec |  ± 2.11 % |              + 729.35 % |\n\n## Install\nBun (Recommended) - `bun add undici-shim`\\\nPNPM - `pnpm i undici-shim`\n\n## Usage\n### ESM\nWhen importing, the `request` method is used by default, though it also works as a named export.\n```ts\nimport request from 'undici-shim'\n// or\nimport { request } from 'undici-shim'\n```\n\nThen simply call it asynchronously and return the response as usual. However, methods like `.json()` and `.text()` have been moved to the body instead of the response like the standard `fetch`.\n```ts\nconst res = await request('https://jsonplaceholder.typicode.com/posts/1')\nconsole.log(await res.body.json())\n```\n\nFor consistency across environments, you can use Undici [fetch](https://undici.nodejs.org/#/?id=undicifetchinput-init-promise) instead.\n```ts\nimport { fetch } from 'undici-shim'\n\nconst res = await fetch('https://jsonplaceholder.typicode.com/posts/1')\nconsole.log(await res.json())\n```\n\n### CommonJS\n```js\nconst { fetch } = require('undici-shim')\n\nfetch('https://jsonplaceholder.typicode.com/posts/1')\n    .then(res =\u003e res.json())\n    .then(console.log)\n```\n\n## Named Exports\n**Node**\u003cbr\u003e\nStarting from v1.3.2, named exports are identical to Undici.\n```js\nimport { request, Dispatcher, Headers, ... } = from 'undici-shim'\n```\n\n**Browser**\n```js\nimport { fetch, Request, Response, Headers } = from 'undici-shim'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowen3h%2Fundici-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowen3h%2Fundici-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowen3h%2Fundici-shim/lists"}