A lightweight middleware library for the Fetch API, version 2.8.3, released monthly with active maintenance. It provides a composable middleware pipeline for fetch requests and responses, similar to koa or express middleware. Key differentiators: minimal (1.2KB gzipped), zero dependencies, supports both browser and Node.js (undici-based fetch), and TypeScript-first with full type inference. Unlike heavier solutions like axios or ky, fetch-run focuses solely on middleware chaining without bundling a fetch polyfill.
npm install fetch-runNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a fetch instance with middleware stack including logging and Bearer token authentication.
Upgrade to Node 18+ or use a fetch polyfill like 'undici' with a custom adapter.
Wrap middleware definitions in a higher-order function: `(next) => async (url, init) => { ... }`Replace `compose(logger, auth)` with `createFetch(logger, auth)`.
Always clone and return a new Response: `const newRes = new Response(res.body, res); return newRes;`
Use `as const` for middleware arrays if needed: `const stack = [logger, auth] as const;`
Pass a custom fetch via `createFetch(middleware, { fetch: customFetch })`.Ensure each middleware is a function returning a function of `(next) => async (url, init) => { ... }` not a direct async function.Always clone response before mutation: `response = new Response(response.body, response)` and then modify headers.
Use `createFetch` instead of `compose` (removed since v2.8). If using older version, import `compose` from 'fetch-run/compose'.
Always return `await next(url, init)` or a new Response at the end of middleware.
No dependency data recorded yet.