Advanced fetch client builder for TypeScript with standard schema validation (Zod, Valibot, ArkType), automatic response parsing, retry, timeout, streaming, progress tracking, and lifecycle hooks. Version 2.6.0 (stable), actively maintained. Lightweight (1.6kB gzipped, no dependencies) and fully type-safe. Requires Node >=18 and ES2020. Differentiator: combines schema validation with familiar fetch API, supports multiple schema libraries via standard-schema, and offers comprehensive features like retry and progress without additional dependencies.
npm install up-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a fetch client with base URL and headers, fetches a user with Zod schema validation, returns parsed and typed response.
Update code to pass `fetch` or a polyfill as the first argument: `up(fetch, options)` instead of `up(options)`.
Wrap Zod schemas as usual (they are compatible), but ensure you're using the correct import: `import { z } from 'zod'`. No change for Zod v3 users.Use `signal: AbortSignal.timeout(5000)` instead of `timeout: 5000`.
Avoid using retry with non-cloneable bodies like streams; pass a plain object or string instead.
Use a custom param serializer via `paramsSerializer` option for nested structures, or manually serialize with URLSearchParams.
Pass the schema object directly (e.g., `schema: UserSchema`) without wrapping; avoid `as const` if not needed.
Install a fetch polyfill (e.g., 'undici' or 'cross-fetch') and pass it as first argument: `up(require('undici').fetch, ...)`.Ensure schema is a valid standard-schema validator (Zod, Valibot, ArkType) and imported correctly. Example: `import { z } from 'zod'; const schema = z.object({...})`.Use the 'errorAsValue' option or 'onError' hook to handle errors. For expected errors, set `errorAsValue: true` and check the result type.
Use `signal: AbortSignal.timeout(ms)` on the request. Ensure environment supports AbortSignal.timeout (Node <18 may need polyfill).
Use dynamic import: `const { up } = await import('up-fetch')` or switch to ESM file (add 'type': 'module' to package.json).No dependency data recorded yet.