A Rust library for interacting with HTTP API endpoints
Rustify is a small library written in Rust which eases the burden of
scaffolding HTTP APIs. It provides an Endpoint
trait along with a macro helper
which allows templating various remote endpoints. Both asynchronous and
synchrounous clients are offered for executing requests against endpoints with
the option of implementing custom clients using the Client
trait.
Rustify provides support for serializing requests and deserializing responses in JSON. Raw requests and responses in the form of bytes are also supported. The library also contains many helpers for dealing with requests like support for middleware and wrapping API responses.
Add rustify as a depdendency to your cargo.toml:
toml
[dependencies]
rustify = "0.4.0"
The below example creates a Test
endpoint that, when executed, will send a GET
request to http://api.com/test/path
and expect an empty response:
```rust use rustify::{Client, Endpoint}; use rustify_derive::Endpoint; use serde::Serialize;
struct Test {}
let endpoint = Test {}; let client = Client::default("http://api.com"); let result = endpoint.exec(&client).await;
assert!(result.is_ok()); ```
You can find example usage in the examples directory. They can be run with cargo:
cargo run --package rustify --example reqres1
cargo run --package rustify --example reqres2
Additionally, the vaultrs is a great reference for a crate which relies heavily on rustify.
The following features are available for this crate:
blocking
: Enables the blocking variants of Client
s as well as the blocking
exec()
functions in Endpoint
s. All errors generated by this crate are wrapped in the ClientError
enum
provided by the crate.
See the the tests directory for tests. Run tests with cargo test
.