Registry / testing / make-fetch

make-fetch

JSON →
library3.2.3jsnpmunverified

A library for implementing a custom fetch() function using Node.js streams. Version 3.2.3 is the current stable release. It allows you to define a handler that processes standard Request objects and returns Response options. It provides a low-level API (makeFetch) for completely custom logic and a higher-level routed API (makeRoutedFetch) for matching URL patterns, supporting wildcards. Ships TypeScript types. Similar to node-fetch but focused on custom protocol implementations.

npm install make-fetch
INSTALL
IMPORT
SIG · MAKE-FETCH
M
make-fetch
testingjavascriptv3.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeFetch
import { makeFetch } from 'make-fetch'
import makeFetch from 'make-fetch'
Default import is not supported; must use named import for makeFetch.
makeRoutedFetch
import { makeRoutedFetch } from 'make-fetch'
import { makeRoutedFetch } from 'make-fetch/routed'
makeRoutedFetch is exported from the main package entry, not a subpath.
Router
import { makeRoutedFetch } from 'make-fetch'; const { router } = makeRoutedFetch()
import { Router } from 'make-fetch'
Router is not directly exported; it is returned as part of makeRoutedFetch() result.

Demonstrates creating a custom fetch using makeFetch with a simple handler and making a request.

import { makeFetch } from 'make-fetch' const fetch = makeFetch(async (request) => { const { url, headers, referrer, method, body, signal } = request // Custom logic: return a response return { status: 200, headers: { 'content-type': 'text/plain' }, body: 'Hello from make-fetch!' } }) const response = await fetch('custom://example.com') console.log(await response.text())
Debug
Known issues
gotchaThe handler must return an object with status, headers, and body properties. Body must be an async iterable of buffers or a string (will be converted).
fix
Ensure handler returns an object with status (number), headers (object optional), and body (async iterable or string).
affects: >=3.0.0
gotchaThe request.body is an optional async iterable of buffers, not a string. To read it, you must iterate over it.
fix
Use a for-await loop to consume the body chunks: for await (const chunk of body) { ... }
affects: >=3.0.0
breakingIn version 3.x, the main exported function is named 'makeFetch', not 'default'. CommonJS require('make-fetch') returns an object with makeFetch.
fix
Use const { makeFetch } = require('make-fetch') instead of const makeFetch = require('make-fetch')
affects: >=3.0.0
gotchaThe router methods (get, post, etc.) return the router for chaining, but the handlers must be synchronous or return a promise; they are not middleware.
fix
Each handler should return a response object directly or via a promise, not call next().
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: makeFetch is not a function
Importing default export instead of named export.
fix
Use import { makeFetch } from 'make-fetch'
TypeError: request.body is not iterable
Assuming request.body is a string, but it is an async iterable of buffers.
fix
Use for await (const chunk of request.body) { ... }
Error: Response body must be provided as string, Buffer, or async iterable
Returning undefined or null body in handler.
fix
Return an object with a body property: either a string or an async iterable.
Upgrade
Version history
3.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
make-fetch — npm install make-fetch · libregistry