reqwest-enum Rust crate

reqwest-enum

Describe your HTTP API as an enum and let reqwest-enum handle URLs, headers, encoding, and decoding.

Rust
Enum
HTTP
JSONRPC

What it is

reqwest-enum is a Rust library that turns the popular reqwest HTTP client into a type-safe, enum-driven API layer. Instead of scattering URL strings, header maps, and serialization logic across your code, you describe each endpoint as a variant of an enum and implement a target trait — reqwest-enum takes care of building the request and deserializing the response. The design is inspired by Swift's Moya, so each API becomes a single, exhaustive definition the compiler can check.

Features

  • Type-safe, enum-style HTTP API that centralizes endpoint definitions.
  • Handles URL formatting, query and header encoding, and response deserialization for you.
  • Async by default, built directly on top of reqwest.
  • Lightweight JSON-RPC support with batching, via the JsonRpcTarget trait.
  • Optional reqwest-middleware integration and per-request customization through closures.

How to use

Add the crate with Cargo, then define your endpoints as an enum, implement the target trait, create a Provider, and call its request methods — request for plain HTTP and request_json for JSON-RPC.

cargo add reqwest-enum

See the README and examples on GitHub for full target and JSON-RPC usage.

Why

Hand-written HTTP clients tend to drift: a typo in a path, a forgotten header, or a mismatched response type only surfaces at runtime. By modeling an API as an enum, reqwest-enum moves those mistakes to compile time and keeps every endpoint in one place — which is especially handy for things like blockchain JSON-RPC providers where the method surface is large and strongly typed.