Registry / devops / micro-ftch

micro-ftch

JSON →
library1.0.0jsnpmunverified

A collection of fetch wrappers providing killswitch, logging, timeouts, concurrency limits, JSON-RPC batching, and replayable requests. Built on top of the browser's native fetch() API, it enables secure network control in environments where raw fetch is insufficient. Version 1.0.0 is stable, with composable wrappers (ftch, jsonrpc, replayable) that can be chained. Unlike heavier alternatives, it focuses on minimal overhead and TypeScript first-class support. Ideal for testing, rate-limited APIs, and secure contexts.

npm install micro-ftch
INSTALL
IMPORT
SIG · MICRO-FTCH
M
micro-ftch
devopsjavascriptv1.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.

ftch
import { ftch } from 'micro-ftch'
const ftch = require('micro-ftch')
ESM-only package; CommonJS not supported. Use dynamic import() if needed.
jsonrpc
import { jsonrpc } from 'micro-ftch'
import jsonrpc from 'micro-ftch'
jsonrpc is a named export, not default. It wraps a fetch function to provide JSON-RPC calls.
replayable
import { replayable } from 'micro-ftch'
import { Replayable } from 'micro-ftch'
replayable is exported as a lowercase function. The name is case-sensitive.

Shows how to create a fetch wrapper with killswitch, logging, concurrency limit, and JSON-RPC batching, plus replayable mode for testing.

import { ftch, jsonrpc, replayable } from 'micro-ftch'; // Killswitch and logging let enabled = true; const f = ftch(fetch, { isValidRequest: () => enabled, log: (url, opts) => console.log('fetching', url, opts), timeout: 5000, concurrencyLimit: 10, }); // Basic fetch const res = await f('https://httpbin.org/get'); console.log(await res.json()); // JSON-RPC with batching const rpc = jsonrpc(fetch, 'https://example.com/rpc', { headers: { 'Content-Type': 'application/json' }, batchSize: 20, }); const result = await rpc.call('method', 'arg0', 'arg1'); console.log(result); // Replayable for testing const replayNet = replayable(f); const replayRes = await replayNet('https://httpbin.org/get'); console.log(await replayRes.json());
Debug
Known issues
gotchaThe package is ESM-only. It cannot be required() from CommonJS modules directly.
fix
Use dynamic import: const { ftch } = await import('micro-ftch'); or switch to ESM.
affects: >=1.0.0
gotchaConcurrencyLimit only limits concurrent requests via the same wrapper instance. Global limits are not enforced.
fix
Ensure you share the same ftch instance across all calls if you want a global limit.
affects: >=1.0.0
gotchaThe timeout option in ftch wraps the fetch promise with a timeout; it does not cancel the underlying HTTP request. The request may still complete in the background.
fix
Use AbortController for full cancellation if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'micro-ftch' or its corresponding type declarations.
Forgetting to install the package or using CommonJS require.
fix
Run 'npm install micro-ftch' and ensure your project uses ESM (set 'type': 'module' in package.json or use .mjs extension).
TypeError: fetch is not a function
Using ftch in an environment without native fetch (e.g., old Node.js versions without fetch).
fix
Polyfill fetch: npm install node-fetch, then import fetch from 'node-fetch'; const f = ftch(fetch, {...});
Uncaught Error: Request blocked by isValidRequest killswitch
The isValidRequest function returned false, preventing the request.
fix
Check the condition that controls the killswitch and toggle it to true.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
micro-ftch — npm install micro-ftch · libregistry