Skip to main content

Module transport

Module transport 

Source
Expand description

The one seam between a decided request and the network.

The vocabulary is http::Request<Vec<u8>> in, http::Response<Vec<u8>> out, which is what every client-agnostic Rust crate converges on (oauth2, rustify, atrium-xrpc, kube-core). There is no de-facto trait, so this crate defines its own two — a sync one and an async one, because a single trait cannot be both and maybe-async makes the flavour a global switch.

This crate ships no adapter and depends on no HTTP client, in any feature combination: an adopter’s choice of client is theirs, and a crate that pinned one would make it everyone’s. examples/toy/cli/src/client.rs has both adapters in full — a ureq 3 agent in nine lines, a reqwest::Client in twelve — written to be copied rather than depended on.

An adapter in an adopter’s crate wraps the client in a newtype, because SyncClient and the client are both foreign there. A crate that owns either one writes impl SyncClient for ureq::Agent directly.

No adapter may turn a status code into an error: the status belongs to the layer above, which needs the body that came with it. ureq does this by default and must be built with http_status_as_error(false).

Structs§

Recorder
A client that sends nothing, answers from a script, and keeps every request it was given.

Traits§

AsyncClient
The same, for a caller inside a runtime. Send on the future so that a call can be tokio::spawned.
SyncClient
Something that can send a request and wait for the answer.

Type Aliases§

HttpRequest
What every adapter takes.
HttpResponse
What every adapter returns.