LogoIndieHub
icon of wretch

wretch

Wretch is a tiny (~2KB g-zipped) wrapper around fetch with an intuitive syntax, designed to simplify network requests and handle responses.

Introduction

Wretch

A tiny (~2KB g-zipped) wrapper built around fetch with an intuitive syntax.

Key Features:

  • Small: Core is less than 2KB g-zipped.
  • Intuitive: Lean API, handles errors, headers, and (de)serialization.
  • Immutable: Every call creates a cloned instance for safe reuse.
  • Modular: Plug addons to add new features and middlewares to intercept requests.
  • Isomorphic: Compatible with modern browsers, Node.js 14+, and Deno.
  • Type Safe: Strongly typed, written in TypeScript.
  • Proven: Fully covered by unit tests and widely used.
  • Maintained: Alive and well for many years.

Use Cases:

Wretch simplifies making HTTP requests in JavaScript applications by providing a more streamlined and intuitive syntax compared to the native fetch API. It's particularly useful for:

  • Reducing boilerplate code: Automates common tasks like JSON serialization and error handling.
  • Improving code readability: Offers a fluent API for chaining request configurations.
  • Enhancing error handling: Automatically throws errors for non-successful HTTP status codes.
  • Facilitating code reuse: Immutability allows for creating pre-configured instances for different APIs.
  • Extending functionality: Addons and middlewares enable customization and integration with other libraries.