pub trait Transport {
type Error: Display;
// Required method
async fn send(
&self,
request: HttpRequest,
) -> Result<HttpResponse, Self::Error>;
}Expand description
The IO seam. A wasm consumer implements it over gloo-net, a native one over
reqwest. The client never constructs URLs beyond the path: the transport
owns the base URL, credentials, and headers.
Authentication and 401 refresh-retry live here, in the transport, not in the client. A transport attaches the credential to every request, and on a 401 it may refresh the token and retry once before returning the response. This is the injection point a real UI needs, and it keeps the client itself auth-agnostic.
The trait uses an async fn in a trait, so the returned future is not bound
Send. A browser (single-threaded wasm) needs nothing more. A native caller
that drives the client on a multi-threaded executor and needs a Send future
(for example to tokio::spawn it) should run the client on a current-thread
runtime or wrap the call in a Send-producing adapter.
Required Associated Types§
Sourcetype Error: Display
type Error: Display
The transport’s own failure type (a network error, a timeout). Surfaced
verbatim through ClientError::Transport.
Required Methods§
Sourceasync fn send(&self, request: HttpRequest) -> Result<HttpResponse, Self::Error>
async fn send(&self, request: HttpRequest) -> Result<HttpResponse, Self::Error>
Perform one request. A non-2xx status is not an error here: the
client inspects the status and decodes the ErrorBody. Return Err
only when the request never produced a response.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".