reqwest_rest/lib.rs
1//! An opinionated utility to help with creating one-off idiomatic REST API clients.
2//!
3//! [`RestClient`] wraps a `reqwest_middleware::ClientWithMiddleware` and provides a uniform API
4//! for making all types of http-json requests and parsing responses as json if possible.
5//! Errors are rich and retain request context, and allow for further processing of unparseable responses.
6//!
7//! Typically means you can define the schema using serde-compatible types, and implement
8//! an RPC-like client over `RestClient` with minimal boilerplate, where each call is 1-2 lines.
9//! To do further API-specific processing of error responses, you can use `map_err` and match against
10//! `Error::Response`, and do whatever you need to with the body of that response.
11//!
12//! Separately from this, [`CommonConfig`] helps to reduce boilerplate when setting up timeouts
13//! and retries with backoff, which is appropriate in most situations that you make rest requests.
14//!
15//! [`LoggingRetryableStrategy`] is a reqwest-retry `RetryStrategy` which logs additional information
16//! when requests need to be retried, and is attached when using `CommonConfig`.
17
18#![deny(missing_docs)]
19
20pub use reqwest;
21pub use reqwest_middleware;
22
23#[cfg(feature = "reqwest-retry")]
24pub use reqwest_retry;
25#[cfg(feature = "reqwest-retry")]
26pub use retry_policies;
27
28mod rest_client;
29pub use rest_client::{
30 ClientWithMiddleware, Error, HeaderMap, Method, ParseError, ReqwestError,
31 ReqwestMiddlewareError, RestClient, SerdeJsonError, SerdeQsError, Url, join_url,
32};
33
34#[cfg(feature = "reqwest-retry")]
35mod common_config;
36#[cfg(feature = "reqwest-retry")]
37pub use common_config::CommonRestConfig;
38
39#[cfg(feature = "reqwest-retry")]
40mod retry_strategy;
41#[cfg(feature = "reqwest-retry")]
42pub use retry_strategy::LoggingRetryableStrategy;