Expand description
An HTTP client for Churust applications.
A service usually has to call other services: an identity provider, a payment gateway, its own sibling. This is the client for that, built on the same hyper the server side runs on, so a Churust binary carries one HTTP implementation rather than two.
use churust_client::Client;
let client = Client::new();
let res = client.get("http://127.0.0.1:8080/health").send().await?;
assert_eq!(res.status().as_u16(), 200);
println!("{}", res.text()?);§Scope
Deliberately small: build a request, send it, read the response. Retries, circuit breaking, service discovery and tracing propagation are policy, and policy belongs to the application that knows what it is calling. What the client does own is the part that is easy to get wrong on your own: pooled connections, an enforced timeout, a bounded response body, and refusing to follow a redirect into a different scheme.
§Responses are bounded
A response body is read into memory up to Client::max_response_bytes
(16 MiB by default) and refused past it. An unbounded read from a service
you do not control is how one slow dependency becomes your own out-of-memory
kill.
§Compressed responses
By default the client advertises Accept-Encoding: gzip, deflate and
transparently inflates those encodings, so a peer that compresses — CDNs,
many affiliate APIs — is not left as a bag of deflate bits on the caller.
The decompressed size is still bounded by Client::max_response_bytes:
a tiny compressed bomb that expands past the ceiling is refused, which is
the same limit that protects against an uncompressed flood. Disable with
Client::auto_decompress(false) when you need the raw bytes or want to
negotiate encoding yourself.
Structs§
- Client
- A pooled HTTP client.
- Request
Builder - A request under construction. Finish it with
send. - Response
- A response, with its body already read.
Enums§
- Client
Error - Everything that can go wrong sending a request.