5 releases

0.2.0 Mar 3, 2024
0.1.1 Aug 15, 2023
0.1.0 Aug 12, 2023
0.1.0-alpha.2 Aug 10, 2023
0.1.0-alpha.1 Aug 7, 2023

#450 in HTTP client

Download history 3/week @ 2024-07-28 2/week @ 2024-09-22 2/week @ 2024-09-29

115 downloads per month

MIT license

43KB
667 lines

restless

ci status book nightly docs nightly docs latest test coverage crate version

REST API wrappers with less pain. This trait exposes helper traits that let you define your API in terms of trait implementations. Useful to remove redundant code if you use Rust on the backend and then frontend. Similar to standards such as OpenAPI, but uses the Rust trait system. The trait implementation gives you API clients for free.

Examples

If you build a useful type that encapsulates all information about your REST request, such as this:

/// GET /api/v1/users/:name/documents/:id
pub struct UserDocument {
    user: String,
    document: Uuid,
}

Then you can implement the GetRequest trait for this type and use the RequestMethod marker.

use restless::{GetRequest, method::Get};

impl GetRequest for UserDocument {
    type Response = Json<Document>;
    type Query = ();

    fn path(&self) -> Cow<'_, str> {
        format!("api/v1/users/{}/documents/{}", self.user, self.document).into()
    }

    fn query(&self) -> Self::Query {}
}

impl RequestMethod for UserDocument {
    type Method = Get<Self>;
}

Now you can make this kind of request using the built-in clients.

Clients

This crate offers integrations with the following HTTP clients and frameworks by enabling the corresponding feature:

Name Description
reqwest Make HTTP requests using the reqwest crate.
gloo Make HTTP requests in WebAssembly Rust applications using the gloo_net crate.
yew Make HTTP requests from within Yew frontend components.

License

MIT, see LICENSE.md

Dependencies

~0.2–8.5MB
~82K SLoC