#rest #http #api #endpoint #client

rustify

A Rust library for interacting with HTTP API endpoints

9 unstable releases (3 breaking)

0.4.4 Sep 11, 2021
0.4.3 Sep 1, 2021
0.4.2 Aug 31, 2021
0.3.1 Aug 21, 2021
0.1.0 Aug 15, 2021

#39 in HTTP client

Download history 36/week @ 2021-08-14 147/week @ 2021-08-21 141/week @ 2021-08-28 86/week @ 2021-09-04 222/week @ 2021-09-11 76/week @ 2021-09-18

171 downloads per month
Used in 3 crates (2 directly)

MIT license

57KB
960 lines

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:

[dependencies]
rustify = "0.4.4"

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 rustify::{Client, Endpoint};
use rustify_derive::Endpoint;
use serde::Serialize;

#[derive(Debug, Endpoint, Serialize)]
#[endpoint(path = "test/path")]
struct Test {}

let endpoint = Test {};
let client = Client::default("http://api.com");
let result = endpoint.exec(&client).await;

assert!(result.is_ok());

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 of Clients as well as the blocking exec() functions in Endpoints.

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

  1. Fork it (https://github.com/jmgilman/rustify/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Dependencies

~4.5–9MB
~217K SLoC