reqwest-enum
Type-safe and enum style API for Rust, some benefits:
- It abstracts away repetitive boilerplate code like url formatting, query / header encoding and response deserialization.
- Type-safe endpoints, readable like a spec, easy to add new or refactor existing endpoints.
- Async by default and lightweight JSON-RPC support.
Features:
- Type-safe and enum style HTTP API
- JSON-RPC with batching support
- ...
Installation
cargo add reqwest-enum
or add it to your Cargo.toml
:
[]
= "0.3.2"
Example
httpbin.org
- Define endpoints for https://httbin.org as an enum:
- Implement
Target
for the enum:
- Create a provider and request:
let provider = default;
let response = provider.request.await.unwrap;
assert_eq!;
Provider also allows you to customize the request by providing a EndpointFn
or RequestBuilderFn
closure if default behavior is not sufficient:
- Need to use different endpoint based on the target.
- Need to insert custom headers or intercept the final request.
JSON-RPC
Full example can be found in examples/ethereum-rpc.
- Define Ethereum JSON-RPC methods as an enum:
- Implement
Target
andJsonRpcTarger
for the enum:
- Create a provider and request:
let provider = default;
let response: =
provider.request_json.await.unwrap;
assert_eq!;
License
MIT or Apache-2.0