Registry / devops / proto-fetch

proto-fetch

JSON →
library2.0.0jsnpmunverified

A protocol handler wrapper for the Fetch API that routes requests based on URL protocol (e.g., file, http, https) to custom fetch implementations. Version 2.0.0 is current; the library is stable with no active development. Unlike a monolithic fetch polyfill, proto-fetch delegates protocol handling to separate fetch modules (like file-fetch or nodeify-fetch), enabling modular and extensible fetching in Node.js and custom runtimes. It does not ship its own fetch implementations and requires an explicit protocol-to-implementation map at construction time.

npm install proto-fetch
INSTALL
IMPORT
SIG · PROTO-FETCH
P
proto-fetch
devopsjavascriptv2.0.0
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.

default
import protoFetch from 'proto-fetch'
const protoFetch = require('proto-fetch')
ESM-only; no default export requires a named import or default import via module.

Demonstrates creating a proto-fetch instance with protocol handlers for file and http/https using separate fetch modules, then fetching a local file.

import fileFetch from 'file-fetch'; import httpFetch from 'nodeify-fetch'; import protoFetch from 'proto-fetch'; const fetch = protoFetch({ [null]: fileFetch, file: fileFetch, http: httpFetch, https: httpFetch }); const res = await fetch(`file://${process.cwd()}/package.json`); const json = await res.json(); console.log(json);
Debug
Known issues
gotchaThe null key in the protocol map (used for protocol-relative URLs) is not commonly known; forgetting it will cause those URLs to fail.
fix
Include [null]: handler in the configuration object for protocol-relative URLs like //example.com/path.
affects: >=1.0.0
gotchaproto-fetch does not validate that the provided handlers are actual fetch functions; passing incorrect types leads to runtime errors.
fix
Ensure each handler is a function that accepts a Request/URL and returns a Promise<Response>.
affects: >=1.0.0
gotchaProtocols must be strings (or null); numbers or other types are not supported and may cause silent failures.
fix
Use string keys for protocols (e.g., 'http', 'https', 'file') and null for protocol-relative URLs.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fetch is not a function
protoFetch returns a wrapper function; calling it directly without the map object yields a non-function.
fix
Call protoFetch with a protocol-to-handler map to get the fetch function: const fetch = protoFetch({file: fileFetch}).
Error: No handler for protocol: ftp
The protocol map does not include a handler for the 'ftp' protocol.
fix
Add a handler for 'ftp' in the map: const fetch = protoFetch({ftp: ftpFetch, ...}).
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
proto-fetch — npm install proto-fetch · libregistry