Skip to main content

Crate reqwest_rest

Crate reqwest_rest 

Source
Expand description

An opinionated utility to help with creating one-off idiomatic REST API clients.

RestClient wraps a reqwest_middleware::ClientWithMiddleware and provides a uniform API for making all types of http-json requests and parsing responses as json if possible. Errors are rich and retain request context, and allow for further processing of unparseable responses.

Typically means you can define the schema using serde-compatible types, and implement an RPC-like client over RestClient with minimal boilerplate, where each call is 1-2 lines. To do further API-specific processing of error responses, you can use map_err and match against Error::Response, and do whatever you need to with the body of that response.

Separately from this, [CommonConfig] helps to reduce boilerplate when setting up timeouts and retries with backoff, which is appropriate in most situations that you make rest requests.

LoggingRetryableStrategy is a reqwest-retry RetryStrategy which logs additional information when requests need to be retried, and is attached when using CommonConfig.

Re-exports§

pub use reqwest;
pub use reqwest_middleware;
pub use reqwest_retry;
pub use retry_policies;

Structs§

ClientWithMiddleware
ClientWithMiddleware is a wrapper around reqwest::Client which runs middleware on every request.
CommonRestConfig
Configuration of timeouts and retries for basic http client, with sane defaults
HeaderMap
A set of HTTP headers
LoggingRetryableStrategy
reqwest_retry helpfully logs something when a request is being retried:
Method
The Request Method (VERB)
ReqwestError
The Errors that may occur when processing a Request.
RestClient
A reqwest client (with middleware) and a base url, which can make “REST” (http-json) requests and parse responses according to serde-schema.
SerdeJsonError
This type represents all possible errors that can occur when serializing or deserializing JSON data.
Url
A parsed URL record.

Enums§

Error
An error which occurs when using the BasicClient
ParseError
Errors that can occur during parsing.
ReqwestMiddlewareError
SerdeQsError
Error type for serde_qs.

Functions§

join_url
When making requests, this client works by appending routes as needed to the base url of the api This function is a helper to work around issues with url::join, where it is sensitive to trailing slashes in the base API, but that is potentially confusing and not usually what we want. https://docs.rs/url/latest/url/struct.Url.html#method.join https://github.com/servo/rust-url/issues/333 Instead we clone the original url and append path segments using the path_segments_mut api. We have to split the route on / for this to work correctly, otherwise the library will escape the / characters… We modeled the splitting procedure on the code in url lib here: https://docs.rs/url/2.5.0/src/url/lib.rs.html#1351