{"_id":"micro-ftch","_rev":"4618339","name":"micro-ftch","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","dist-tags":{"latest":"0.5.0"},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"time":{"modified":"2026-04-10T18:17:42.000Z","created":"2020-06-24T12:05:40.544Z","0.5.0":"2025-06-04T08:51:30.562Z","0.4.3":"2025-03-28T19:33:13.859Z","0.4.2":"2025-01-23T05:40:54.480Z","0.4.1":"2025-01-09T20:55:58.084Z","0.4.0":"2024-06-16T02:14:06.521Z","0.3.1":"2021-07-08T04:10:57.976Z","0.3.0":"2021-07-06T04:57:27.477Z","0.2.0":"2021-06-05T03:02:06.247Z","0.1.1":"2020-06-24T12:05:40.544Z"},"users":{},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"versions":{"0.5.0":{"name":"micro-ftch","version":"0.5.0","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","devDependencies":{"@paulmillr/jsbt":"0.4.1","@types/node":"22.15.23","micro-bmark":"0.4.1","micro-should":"0.5.3","prettier":"3.5.2","typescript":"5.8.3"},"sideEffects":false,"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-ftch","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"type":"module","main":"./index.js","module":"./index.js","types":"./index.d.ts","scripts":{"build":"tsc","build:release":"npx jsbt esbuild test/build","lint":"prettier --check index.ts","format":"prettier --write index.ts","test":"node --experimental-strip-types --no-warnings test/index.ts","test:bun":"bun test/index.ts","test:deno":"deno --allow-env --allow-net test/index.ts"},"keywords":["fetch","network","killswitch","concurrent","parallel","jsonrpc","micro","replay","ftch"],"funding":"https://paulmillr.com/funding/","_id":"micro-ftch@0.5.0","gitHead":"d9acb944ff7275746189b9ecf88a3cae3a3dab00","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"shasum":"40b77fb9fba24185fa0438afd006b2834b81b0d6","size":14211,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.5.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.5.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-ftch_0.5.0_1749027090389_0.8564724815629108"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-06-04T08:51:30.562Z","publish_time":1749027090562,"_source_registry_name":"default","_cnpm_publish_time":1749027090562},"0.4.3":{"name":"micro-ftch","version":"0.4.3","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","main":"./lib/index.js","module":"./lib/esm/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/esm/index.js","default":"./lib/index.js"}},"devDependencies":{"@paulmillr/jsbt":"0.3.3","micro-bmark":"0.4.0","micro-should":"0.5.1","prettier":"3.5.2","typescript":"5.8.2"},"sideEffects":false,"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-ftch","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"scripts":{"build":"tsc && tsc -p tsconfig.cjs.json","build:release":"npx jsbt esbuild test/build","lint":"prettier --check index.ts","format":"prettier --write index.ts","test":"node test/index.js","test:bun":"bun test/index.js","test:deno":"deno --allow-env --allow-net test/index.js"},"keywords":["fetch","network","killswitch","concurrent","parallel","jsonrpc","replay","ftch"],"funding":"https://paulmillr.com/funding/","_id":"micro-ftch@0.4.3","gitHead":"48c4b8599407f54ce2d84d945b49c61f8877c00c","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"shasum":"9a080c80884cf2e241bcc4216361b8cd5410eb42","size":15871,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.4.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.4.3.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-ftch_0.4.3_1743190393656_0.866015543737225"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-03-28T19:33:13.859Z","publish_time":1743190393859,"_source_registry_name":"default","_cnpm_publish_time":1743190393859},"0.4.2":{"name":"micro-ftch","version":"0.4.2","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","main":"./lib/index.js","module":"./lib/esm/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/esm/index.js","default":"./lib/index.js"}},"devDependencies":{"@paulmillr/jsbt":"0.3.1","micro-bmark":"0.4.0","micro-should":"0.5.1","prettier":"3.3.2","typescript":"5.5.2"},"sideEffects":false,"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-ftch","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"scripts":{"build":"tsc && tsc -p tsconfig.cjs.json","build:release":"npx jsbt esbuild test/build","lint":"prettier --check index.ts","format":"prettier --write index.ts","test":"node test/index.js","test:bun":"bun test/index.js","test:deno":"deno --allow-env --allow-net test/index.js"},"keywords":["fetch","network","killswitch","concurrent","parallel","jsonrpc","replay","ftch"],"funding":"https://paulmillr.com/funding/","_id":"micro-ftch@0.4.2","gitHead":"0d77da01a7f2c10ad8adda240936cb5ab061808c","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"shasum":"79b993a9fe7fb9a5c456fa24de833fa80f8ef2dd","size":15596,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.4.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.4.2.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-ftch_0.4.2_1737610854296_0.020131990920092324"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-01-23T05:40:54.480Z","publish_time":1737610854480,"_source_registry_name":"default","_cnpm_publish_time":1737610854480},"0.4.1":{"name":"micro-ftch","version":"0.4.1","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","main":"./lib/index.js","module":"./lib/esm/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/esm/index.js","default":"./lib/index.js"}},"devDependencies":{"@paulmillr/jsbt":"0.2.1","micro-should":"0.4.0","prettier":"3.3.2","typescript":"5.5.2"},"sideEffects":false,"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-ftch","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"scripts":{"build":"tsc && tsc -p tsconfig.esm.json","lint":"prettier --check index.ts","format":"prettier --write index.ts","test":"node test/index.test.js"},"keywords":["fetch","network","killswitch","concurrent","parallel","jsonrpc","replay","ftch"],"funding":"https://paulmillr.com/funding/","_id":"micro-ftch@0.4.1","gitHead":"8f7a6ed6a9afe3f781d685b17c2727ce00da2294","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"_nodeVersion":"20.18.1","_npmVersion":"10.8.2","dist":{"shasum":"2562c48b5d913aed8aff6efd4cce21bad56fd88a","size":15524,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.4.1.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-ftch_0.4.1_1736456157919_0.08679052212519345"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-01-09T20:55:58.084Z","publish_time":1736456158084,"_source_registry_name":"default","_cnpm_publish_time":1736456158084},"0.4.0":{"name":"micro-ftch","version":"0.4.0","description":"Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features","main":"lib/index.js","module":"lib/esm/index.js","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/esm/index.js","default":"./lib/index.js"}},"devDependencies":{"@paulmillr/jsbt":"0.1.0","micro-should":"0.4.0","prettier":"3.1.1","typescript":"5.3.2"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-ftch","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-ftch.git"},"scripts":{"build":"tsc && tsc -p tsconfig.esm.json","lint":"prettier --check index.ts","format":"prettier --write index.ts","test":"node test/index.test.js"},"keywords":["fetch","network","killswitch","concurrent","parallel","jsonrpc","replay","ftch"],"funding":"https://paulmillr.com/funding/","_id":"micro-ftch@0.4.0","gitHead":"e65b884fcb7dfe8bd58ce3a78a93c70bf57bd054","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"_nodeVersion":"20.14.0","_npmVersion":"10.8.1","dist":{"shasum":"b2c5320b5db934dcb9678eaa5461c24e992d97d6","size":14478,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.4.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-ftch_0.4.0_1718504046342_0.15267972369511895"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-06-16T02:14:06.521Z","publish_time":1718504046521,"_source_registry_name":"default","_cnpm_publish_time":1718504046521},"0.3.1":{"name":"micro-ftch","version":"0.3.1","description":"Wraps nodejs built-in modules and browser fetch into one function.","main":"index.js","scripts":{"bench":"node test/bench.js","build":"tsc -d","test":"node test/node.js"},"keywords":["fetch","http","https","node","browser","ajax","request"],"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","devDependencies":{"@types/node":"^16.0","typescript":"^4.3.5"},"gitHead":"d1e98faea55fd71b8e97353f673c1d1be6ead518","_id":"micro-ftch@0.3.1","_nodeVersion":"16.2.0","_npmVersion":"7.16.0","dist":{"shasum":"6cb83388de4c1f279a034fb0cf96dfc050853c5f","size":4292,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.3.1.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-ftch_0.3.1_1625717457785_0.1708303544158265"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T04:45:32.262Z","publish_time":1625717457976,"_cnpm_publish_time":1625717457976},"0.3.0":{"name":"micro-ftch","version":"0.3.0","description":"Wraps nodejs built-in modules and browser fetch into one function.","main":"index.js","scripts":{"bench":"node test/bench.js","build":"tsc -d","test":"node test/node.js"},"keywords":["fetch","http","https","node","browser","ajax","request"],"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","devDependencies":{"@types/node":"^16.0","typescript":"^4.3.5"},"gitHead":"9f6e2055b076117ef4432e481262b5bbee10a907","_id":"micro-ftch@0.3.0","_nodeVersion":"16.2.0","_npmVersion":"7.16.0","dist":{"shasum":"67364fc190c494fe211b1b59d5b0852c1bfa6aa3","size":4232,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.3.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-ftch_0.3.0_1625547447368_0.9509188418192105"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T04:45:31.182Z","publish_time":1625547447477,"_cnpm_publish_time":1625547447477},"0.2.0":{"name":"micro-ftch","version":"0.2.0","description":"Wraps nodejs built-in modules and browser fetch into one function.","main":"index.js","scripts":{"bench":"node test/bench.js","build":"tsc -d","test":"node test/node.js"},"keywords":["fetch","http","https","node","browser","ajax","request"],"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","devDependencies":{"@types/node":"^14.0.14","typescript":"^4.3.2"},"gitHead":"5d11ff5b010948050685c95729d8deaff04c27e0","_id":"micro-ftch@0.2.0","_nodeVersion":"16.2.0","_npmVersion":"7.16.0","dist":{"shasum":"67b2a4138c066328ed8765c2adf5f84b93e8b85d","size":3230,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.2.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-ftch_0.2.0_1622862126073_0.0019365359258167736"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T04:45:30.327Z","publish_time":1622862126247,"_cnpm_publish_time":1622862126247},"0.1.1":{"name":"micro-ftch","version":"0.1.1","description":"Wraps nodejs built-in modules and browser fetch into one function.","main":"index.js","scripts":{"build":"tsc -d","test":"echo \"Error: no test specified\" && exit 1"},"keywords":["fetch","http","https","node","browser","ajax","request"],"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","devDependencies":{"@types/node":"^14.0.14","typescript":"^3.9.5"},"gitHead":"9bc2694d1329a62142805961afd210be738e4a15","_id":"micro-ftch@0.1.1","_nodeVersion":"14.2.0","_npmVersion":"6.14.5","dist":{"shasum":"99c560aaba661ed882fe0b1039391b69791e4da6","size":2426,"noattachment":false,"key":"/micro-ftch/-/micro-ftch-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-ftch/download/micro-ftch-0.1.1.tgz"},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-ftch_0.1.1_1593000340430_0.7967527946119359"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T04:45:29.437Z","publish_time":1593000340544,"_cnpm_publish_time":1593000340544}},"readme":"# micro-ftch\n\nWrappers for [built-in fetch()](https://developer.mozilla.org/en-US/docs/Web/API/fetch) enabling killswitch, logging, concurrency limit and other features.\n\nfetch is great, however, its usage in secure environments is complicated. The library makes it simple.\n\n## Usage\n\nA standalone file\n[micro-ftch.js](https://github.com/paulmillr/micro-ftch/releases) is also available.\n\n> `npm install micro-ftch`\n\n> `jsr add jsr:@paulmillr/micro-ftch`\n\n```ts\nimport { ftch, jsonrpc, replayable } from 'micro-ftch';\n\nlet enabled = false;\nconst net = ftch(fetch, {\n  isValidRequest: () => enabled,\n  log: (url, options) => console.log(url, options),\n  timeout: 5000,\n  concurrencyLimit: 10,\n});\nconst res = await net('https://example.com');\n\n// Composable\nconst rpc = jsonrpc(net, 'http://rpc_node/', {\n  headers: {},\n  batchSize: 20,\n});\nconst res1 = await rpc.call('method', 'arg0', 'arg1');\nconst res2 = await rpc.callNamed('method', { arg0: '0', arg1: '1' }); // named arguments\nconst testRpc = replayable(rpc);\n// Basic auth auto-parsing\nawait net('https://user:pwd@httpbin.org/basic-auth/user/pwd');\n```\n\n- [ftch](#ftch)\n  - [isValidRequest](#isValidRequest)\n  - [log](#log)\n  - [timeout](#timeout)\n  - [concurrencyLimit](#concurrencyLimit)\n  - [Basic auth](#basic-auth)\n- [jsonrpc](#jsonrpc)\n- [replayable](#replayable)\n- [Privacy](#privacy)\n- [License](#license)\n\nThere are three wrappers over `fetch()`:\n\n1. `ftch(fetch)` - isValidRequest, logging, timeouts, concurrency limits, basic auth\n2. `jsonrpc(fetch)` - batched JSON-RPC functionality\n3. `replayable(fetch)` - log & replay network requests without actually calling network code.\n\n## ftch\n\nBasic wrapper over `fetch()`.\n\n### isValidRequest\n\nWhen isValidRequest killswitch is enabled, all requests will throw an error.\nYou can dynamically enable and disable it any any time.\n\n```ts\nlet ENABLED = true;\nconst f = ftch(fetch, { isValidRequest: () => ENABLED });\nf('http://localhost'); // ok\nENABLED = false;\nf('http://localhost'); // throws\nENABLED = true;\nf('http://localhost'); // ok\n```\n\n### log\n\n```ts\nconst f = ftch(fetch, { log: (url, opts) => console.log('fetching', url, opts) });\nf('http://url/'); // will print request information\n```\n\n### timeout\n\n```ts\n// browser and OS may have additional timeouts, we cannot override them\n// a: per-request timeout\nconst f = ftch(fetch);\nconst res = await f('http://url/', { timeout: 1000 }); // throws if request takes more than one second\n\n// b: timeout for all\nconst f = ftch(fetch, { timeout: 1000 });\nconst res = await f('http://url/'); // throws if request takes more than one second\n```\n\n### concurrencyLimit\n\nAllows to not accidentally hit rate limits or do DoS.\n\n```ts\n// browser and OS may have additional limits, we cannot override them\nconst f = ftch(fetch, { concurrencyLimit: 1 });\nconst res = await Promise.all([f('http://url1/'), f('http://url2/')]); // these would be processed sequentially\n```\n\n### Basic auth\n\n```ts\nconst f = ftch(fetch);\nconst res = await f('https://user:pwd@httpbin.org/basic-auth/user/pwd'); // supports basic auth!\n```\n\n### jsonrpc\n\nSupports batching multiple HTTP requests into one \"Batched\" JSON RPC HTTP request. Can massively speed-up when servers are single-threaded, has small per-user limits\n\n```ts\nconst rpc = jsonrpc(fetch, 'http://rpc_node/', {\n  headers: {},\n  batchSize: 20,\n});\nconst res = await rpc.call('method', 'arg0', 'arg1');\nconst res2 = await rpc.callNamed('method', { arg0: '0', arg1: '1' }); // named arguments\n```\n\n### replayable\n\nSmall utility to log & replay network requests in tests, without actually calling network code.\n\n```ts\nconst ftch = ftch(fetch);\nconst replayCapture = replayable(ftch); // wraps fetch\nawait replayCapture('http://url/1'); // real network\nawait replayCapture('http://url/2');\nconst logs = replayCapture.export(); // Exports logs\n\n// When logs provided - use cached version (faster)\nconst replayTest = replayable(ftch, JSON.parse(logs));\nawait replayTest('http://url/1'); // cached\nawait replayTest('http://url/2'); // cached\nawait replayTest('http://url/3'); // real network\n\n// When done and everything is captured, turn on 'offline' mode to throw on network requests:\nconst replayTestOffline = replayable(ftch, JSON.parse(logs), {\n  offline: true,\n});\nawait replayTest('http://url/1'); // cached\nawait replayTest('http://url/2'); // cached\nawait replayTest('http://url/3'); // throws!\n```\n\n## Privacy\n\nftch() disables referrer by default by setting `referrerPolicy: 'no-referrer'`.\n\n## License\n\nMIT (c) Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file.\n","_attachments":{},"homepage":"https://github.com/paulmillr/micro-ftch","bugs":{"url":"https://github.com/paulmillr/micro-ftch/issues"},"license":"MIT"}