restless/
lib.rs

1//! # restless
2//!
3//! This is a crate that helps you specify your REST API in a typesafe manner. This is somewhat
4//! similar to standards such as [OpenAPI](https://www.openapis.org/), which allow you to specify
5//! your API in a cross-language manner. However, if both your frontend and your backend are
6//! written in Rust, it is not neccessary to go through the trouble of specifying your APIs in a
7//! spec like this. Rather, you can use the trait system to define your requests like this:
8//!
9//! ```rust
10//! use restless::{*, data::Json};
11//! use std::borrow::Cow;
12//!
13//! struct MyRequest {
14//!     name: String,
15//! }
16//!
17//! impl GetRequest for MyRequest {
18//!     type Response = Json<Vec<String>>;
19//!     type Query = ();
20//!
21//!     fn query(&self) -> Self::Query {}
22//!     fn path(&self) -> Cow<'_, str> {
23//!         "api/v1/my-request".into()
24//!     }
25//! }
26//! ```
27//!
28//! In this case, the response type is a JSON-encoded `Vec<String>`. Under the hood, `serde_json`
29//! is used to provide this encoding. This crate ships with other encoding strategies, such as
30//! using [`Yaml`](data::Yaml) or [`Bincode`](data::Bincode). You can also specify
31//! [`Bytes`](bytes::Bytes) to get the raw data. By implementing the [`Decodable`](data::Decodable)
32//! trait, you can augment it with your own, custom decoding strategy. The same goes for request
33//! bodies with the [`Encodable`](data::Encodable) trait.
34//!
35//! ## Clients
36//!
37//! What you get "for free" from this crate is implementations of various clients. See the
38//! [`clients`] module for more information.
39//!
40//! ## Examples
41//!
42//! To see some examples for how this crate may be used, refer to the `examples/` directory in the
43//! [repository](https://github.com/xfbs/restless).
44#![warn(missing_docs)]
45
46/// Integrations with HTTP clients.
47pub mod clients {
48    #[cfg(feature = "gloo")]
49    pub use restless_gloo::*;
50
51    #[cfg(feature = "yew")]
52    pub use restless_yew::*;
53
54    #[cfg(feature = "hyper")]
55    pub use restless_hyper::*;
56
57    #[cfg(feature = "axum")]
58    pub use restless_axum::*;
59
60    #[cfg(feature = "wasm-cache")]
61    pub use restless_wasm_cache::*;
62}
63
64/// Encoding traits and types.
65///
66/// Used to modify how request and response bodies are encoded and decoded.
67pub mod data {
68    pub use restless_core::{Decodable, Encodable};
69    pub use restless_data::*;
70}
71
72/// Method wrappers.
73pub mod methods {
74    pub use restless_core::methods::*;
75}
76
77/// Query mappers.
78pub mod query {
79    pub use restless_query::*;
80}
81
82pub use restless_core::{
83    DeleteRequest, GetRequest, HeadRequest, Method, PatchRequest, PostRequest, Request,
84    RequestMethod, RequestType,
85};
86
87#[cfg(feature = "util")]
88/// Utility traits.
89pub mod util {
90    pub use restless_util::*;
91}
92
93#[cfg(feature = "util")]
94pub use util::RequestExt;