A tiny (~1.8KB g-zipped) wrapper around the Fetch API with an intuitive, chainable syntax. v3.0.8 (latest) is actively maintained and supports modern browsers, Node.js 22+, Deno, and Bun. Key differentiators: immutable API (cloning for reuse), automatic JSON serialization/deserialization, error handling via status-specific handlers (notFound, internalError, etc.), addon/middleware system, and full TypeScript types. Compared to alternatives like ky or axios, wretch is lighter and focuses on a minimal, functional style.
npm install wretchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage of wretch: create an API client, perform GET/POST requests, handle errors with status-specific callbacks, and retrieve responses as JSON, text, raw Response, or Blob.
Use import syntax (import wretch from 'wretch') and ensure your project is ESM (e.g., package.json type: module).
Replace new wretch(...) with wretch(...) (no new keyword).
Use error.status and error.message instead of error.statusCode and error.text.
Use status-specific handlers (.notFound(), .internalError(), etc.) instead of .error() if you need fine-grained control.
Replace .body() with .content() for setting request body content types.
Upgrade Node.js to 22+ or use wretch v2 (but v2 is in maintenance mode).
Switch your project to ESM (add "type": "module" to package.json) or use dynamic import() instead of require().
Remove the new keyword: const api = wretch('https://example.com').Replace .body(contentType) with .content(contentType).
Use error.status instead of error.statusCode.
No dependency data recorded yet.