rustify
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.
Installation
Add rustify as a depdendency to your cargo.toml:
[]
= "0.4.0"
Usage
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:
use ;
use Endpoint;
use Serialize;
let endpoint = Test ;
let client = default;
let result = endpoint.exec.await;
assert!;
Examples
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.
Features
The following features are available for this crate:
blocking
: Enables the blocking variants ofClient
s as well as the blockingexec()
functions inEndpoint
s.
Error Handling
All errors generated by this crate are wrapped in the ClientError
enum
provided by the crate.
Testing
See the the tests directory for tests. Run tests with cargo test
.
Contributing
- Fork it (https://github.com/jmgilman/rustify/fork)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request