pub struct Client { /* private fields */ }Expand description
Sends the requests of a generated client through a tower service.
Client::default sends with reqwest (feature reqwest) and retries transient failures (feature retry).
Client::from_service takes any other service, as is, and Client::layer wraps the current one in a tower
layer:
use std::time::Duration;
use timvw_rust_runtime::Client;
let client = Client::default().layer(tower::timeout::TimeoutLayer::new(Duration::from_secs(30)));Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
Available on crate feature reqwest only.
pub fn new() -> Self
reqwest only.A client that sends with a new reqwest::Client, retrying with RetryPolicy::default (feature retry).
Sourcepub fn from_reqwest(client: Client) -> Self
Available on crate feature reqwest only.
pub fn from_reqwest(client: Client) -> Self
reqwest only.A client that sends with the given reqwest::Client, for example one with a proxy or a custom TLS setup, and
retries like Client::new.
For other retries, or none, start from the bare service instead:
Client::from_service(ReqwestService::new(client)), then add the layers you want.
Sourcepub fn from_service<S, B>(service: S) -> Self
pub fn from_service<S, B>(service: S) -> Self
A client that sends with any tower service from http::Request<Body> to http::Response<B>.
The service must be Clone and Send, not Sync: services such as ConcurrencyLimit that cannot be shared
between threads are held behind a lock that is only taken to clone them. On WebAssembly
(target_family = "wasm") it need not be Send either (MaybeSend), nor its future and body.
Sourcepub fn layer<L, B>(self, layer: L) -> Selfwhere
L: Layer<HttpService>,
L::Service: Service<Request<Body>, Response = Response<B>> + Clone + MaybeSend + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<BoxError>,
<L::Service as Service<Request<Body>>>::Future: MaybeSend + 'static,
B: Body + MaybeSend + MaybeSync + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
pub fn layer<L, B>(self, layer: L) -> Selfwhere
L: Layer<HttpService>,
L::Service: Service<Request<Body>, Response = Response<B>> + Clone + MaybeSend + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<BoxError>,
<L::Service as Service<Request<Body>>>::Future: MaybeSend + 'static,
B: Body + MaybeSend + MaybeSync + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
Wraps the client’s service in a tower layer: retries, timeouts, rate limits, tracing, …
Layers apply from the inside out: the last one added sees a request first.
Sourcepub fn service(&self) -> &HttpService
pub fn service(&self) -> &HttpService
The service requests go through.
Sourcepub fn request(&self, method: Method, url: &str) -> RequestBuilder
pub fn request(&self, method: Method, url: &str) -> RequestBuilder
Starts a request to url.
Trait Implementations§
Source§impl Default for Client
With feature reqwest Client::new: reqwest, with retries when feature retry is on; without it a client
whose every request fails, to be replaced with Client::from_service.
impl Default for Client
With feature reqwest Client::new: reqwest, with retries when feature retry is on; without it a client
whose every request fails, to be replaced with Client::from_service.