{"name":"fetch-extras","version":"2.0.0","keywords":["fetch","whatwg","api","request","response","http","client","httperror","utilities","wrapper","ky","got","axios"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"fetch-extras@2.0.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/fetch-extras#readme","bugs":{"url":"https://github.com/sindresorhus/fetch-extras/issues"},"xo":{"rules":{"n/no-unsupported-features/node-builtins":"off"}},"dist":{"shasum":"d034427902c56176faf74f3554778aeb368a4ccd","tarball":"http://registry-npm.ywwl.com/fetch-extras/download/fetch-extras-2.0.0.tgz","fileCount":41,"integrity":"sha512-4A7651mmbHDFtYAXoZoHrxt5WEniqUe1Lp+b3Ikh9tylfkmBIj5HFpybFT8+MstJXQWQCgATeKwJ2mmd03eMcw==","signatures":[{"sig":"MEYCIQDSMH4Vf4iKowPBGgB0l2IqkBYnVyN+FXf4UGWYkXYQ5AIhAKXnhE5Zu6y9uxgoN74YOgd8dnoNDdu1oBmdYF5Ab+A5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":140287,"size":32542,"noattachment":false,"key":"/fetch-extras/-/fetch-extras-2.0.0.tgz"},"type":"module","engines":{"node":">=22"},"exports":{"types":"./source/index.d.ts","default":"./source/index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"34817105bff8fbef20d94fb5a3ce38ce49188f5d","scripts":{"test":"xo && ava && tsc source/index.d.ts && tsc --noEmit --module node16 --moduleResolution node16 --target es2024 test-d.ts"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/fetch-extras.git","type":"git"},"_npmVersion":"11.12.0","description":"Useful utilities for working with Fetch","directories":{},"sideEffects":false,"_nodeVersion":"25.8.0","dependencies":{"is-network-error":"^1.3.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.60.0","ava":"^7.0.0","typescript":"^6.0.2"},"_npmOperationalInternal":{"tmp":"tmp/fetch-extras_2.0.0_1775677384454_0.8030491327243456","host":"s3://npm-registry-packages-npm-production"},"readme":"<h1 align=\"center\" title=\"fetch-extras\">\n\t<img src=\"media/logo.jpg\" alt=\"fetch-extras logo\">\n</h1>\n\n> Useful utilities for working with [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)\n\nBuild tiny, focused HTTP clients by composing only the features you need on top of the standard `fetch` API. No wrapper objects, no new interface to learn, no lock-in.\n\n## Highlights\n\n- **Composable** — Each `with*` function adds a single capability. Stack them to build exactly the client you need.\n- **Works everywhere** — Browsers, Node.js, Deno, Bun, Cloudflare Workers, etc.\n- **Zero dependencies**\n- **Standard `fetch`** — The input and output are always a plain `fetch` function. Your code stays portable and familiar.\n- **Tree-shakeable** — Only the utilities you import end up in your bundle.\n- **TypeScript** — Full type definitions with strong generics.\n- **Schema validation** — Validate responses against [Standard Schema](https://standardschema.dev) (Zod, Valibot, ArkType, etc.).\n\n*For a full-featured HTTP client on top of Fetch, check out my [`ky`](https://github.com/sindresorhus/ky) package.*\n\n## Install\n\n```sh\nnpm install fetch-extras\n```\n\n## Usage\n\n```js\nimport {\n\tpipeline,\n\twithTimeout,\n\twithBaseUrl,\n\twithHeaders,\n\twithHttpError,\n\twithJsonResponse,\n} from 'fetch-extras';\n\n// Create a tiny reusable API client that:\n// - Times out after 5 seconds\n// - Uses a base URL so you only write paths\n// - Sends auth headers on every request\n// - Throws errors for non-2xx responses\n// - Parses JSON responses automatically\nconst apiFetch = pipeline(\n\tfetch,\n\twithTimeout(5000),\n\twithBaseUrl('https://api.example.com'),\n\twithHeaders({Authorization: 'Bearer token'}),\n\twithHttpError(),\n\twithJsonResponse(),\n);\n\nconst data = await apiFetch('/users');\n```\n\n`pipeline()` order is the documented order throughout this package. Runtime wrapper nesting is the inverse, so `pipeline(fetch, withTimeout(5000), withHeaders(headers))` becomes `withHeaders(headers)(withTimeout(5000)(fetch))`.\n\n## API\n\n### Wrappers\n\nListed in the recommended [`pipeline`](docs/pipeline.md) order. Read the list top to bottom as the order you pass wrappers to `pipeline()`.\n\n- [`withTimeout`](docs/with-timeout.md) - Abort requests that take too long\n- [`withBaseUrl`](docs/with-base-url.md) - Resolve relative URLs against a base URL\n- [`withSearchParameters`](docs/with-search-parameters.md) - Attach default query parameters to every request\n- [`withHeaders`](docs/with-headers.md) - Attach default headers to every request\n- [`withJsonBody`](docs/with-json-body.md) - Auto-stringify plain objects as JSON\n- [`withRateLimit`](docs/with-rate-limit.md) - Enforce client-side rate limiting with a sliding window\n- [`withConcurrency`](docs/with-concurrency.md) - Cap how many requests can run simultaneously\n- [`withDeduplication`](docs/with-deduplication.md) - Collapse concurrent identical GET requests into a single call\n- [`withCache`](docs/with-cache.md) - In-memory caching for plain unconditional GET responses with a TTL\n- [`withDownloadProgress`](docs/with-download-progress.md) - Track download progress\n- [`withUploadProgress`](docs/with-upload-progress.md) - Track upload progress\n- [`withRetry`](docs/with-retry.md) - Retry failed requests with exponential backoff\n- [`withTokenRefresh`](docs/with-token-refresh.md) - Auto-refresh auth tokens on 401 and retry\n- [`withHooks`](docs/with-hooks.md) - `beforeRequest` and `afterResponse` hooks\n- [`withHttpError`](docs/http-error.md#withhttperrorfetchfunction) - Throw on non-2xx responses\n\nChoose one terminal response wrapper:\n\n- [`withJsonResponse`](docs/with-json-response.md) - Parse response as JSON, with optional [Standard Schema](https://standardschema.dev) validation\n- [`withResponse`](docs/with-response.md) - Transform the final response into any value\n\n### Utilities\n\n- [`pipeline`](docs/pipeline.md) - Compose `with*` wrappers without deep nesting\n- [`paginate`](docs/paginate.md) - Async-iterate over paginated API endpoints\n- [`throwIfHttpError`](docs/http-error.md#throwifhttperrorresponse) - Throw if a response is non-2xx\n\n### Errors\n\n- [`HttpError`](docs/http-error.md#httperror) - Error class for non-2xx responses\n- [`SchemaValidationError`](docs/schema-validation-error.md) - Error class for schema validation failures\n\n## FAQ\n\n### How is this different from Ky?\n\n[Ky](https://github.com/sindresorhus/ky) is a full-featured HTTP client with its own API (`ky.get()`, `.json()`, etc.). This package instead gives you individual utilities that wrap the standard `fetch` function. You pick only what you need and compose them together. If you want a batteries-included client, use Ky. If you want to stay close to the `fetch` API while adding specific capabilities, use this.\n\n### How do I use a proxy?\n\nThis package wraps the standard `fetch` API, so proxy support comes from the runtime. In Node.js, use the [`--use-env-proxy`](https://nodejs.org/learn/http/enterprise-network-configuration) flag.\n\n## Related\n\n- [is-network-error](https://github.com/sindresorhus/is-network-error) - Check if a value is a Fetch network error\n- [ky](https://github.com/sindresorhus/ky) - HTTP client based on Fetch\n- [parse-sse](https://www.npmjs.com/package/parse-sse) - Parse Server-Sent Events (SSE) from a Response\n","publish_time":1775677384626,"_cnpm_publish_time":1775677384626,"dist-tags":{"latest":"3.2.1"}}