A tiny wrapper built around fetch with an intuitive syntax for making HTTP requests.
Wretch is a tiny JavaScript library that wraps the native Fetch API with a more intuitive and chainable syntax. It simplifies making HTTP requests by automatically handling JSON serialization, error catching, and request configuration, reducing the boilerplate code typically required with fetch. It solves the problem of verbose and repetitive network request code in modern web applications.
Frontend and full-stack JavaScript/TypeScript developers who frequently make HTTP requests and want a cleaner, more maintainable alternative to raw fetch or heavier HTTP clients.
Developers choose Wretch for its minimal footprint (~1.8KB gzipped), elegant API that reduces fetch boilerplate, and extensible design through addons and middlewares. It offers better error handling, immutability for safe reuse, and full TypeScript support out of the box.
A tiny wrapper built around fetch with an intuitive syntax. :candy:
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a cleaner syntax than raw fetch, with methods like .json() and .post() that automatically handle serialization and headers, reducing boilerplate code as shown in the README examples.
Includes catchers for common HTTP status codes (e.g., .notFound(), .unauthorized()), eliminating the need for manual error checking and throwing, which simplifies response handling.
Supports addons (e.g., for progress tracking, form data) and middlewares (e.g., retry, dedupe) that can be plugged in to extend functionality without bloating the core library.
Works seamlessly in modern browsers, Node.js 22+, Deno, and Bun, making it suitable for isomorphic applications as highlighted in the compatibility section.
Written in TypeScript, offering strong typing for requests and responses, which enhances developer experience and code safety, with examples provided in the README.
Does not work out-of-the-box in Cloudflare Workers due to a missing Response.type property, requiring a custom middleware workaround as documented in the limitations section.
Inherits fetch's case-insensitive headers, which can lead to duplicate header values if set with different cases, and Wretch doesn't automatically deduplicate them, potentially causing issues.
Major version upgrades (e.g., v2 to v3) introduce breaking changes, necessitating code migrations as indicated by the provided migration guides, which can be disruptive for teams.
Advanced functionalities like retry logic or caching require importing separate middlewares, adding complexity and dependencies for teams needing those features out-of-the-box.