Expand description
Outbound HTTP/1.1 client.
A minimal synchronous HTTP/1.1 + HTTPS client with no third-party HTTP
dependency. TLS is backed by rustls (the same crate used by the server’s
inbound TLS stack).
§Plain HTTP (always available)
use rust_web_server::http_client::Client;
let resp = Client::new()
.get("http://httpbin.org/get")
.header("X-Request-Id", "abc123")
.timeout_ms(5_000)
.send()
.unwrap();
assert!(resp.is_success());
println!("{}", resp.text().unwrap());§HTTPS
Requires the http-client feature (or http2/http3, which already pull
in rustls):
[dependencies]
rust-web-server = { version = "17", features = ["http-client"] }Then use exactly the same API — the scheme in the URL selects the transport.
§Async client
Gated on the http2 feature:
use rust_web_server::http_client::AsyncClient;
let resp = AsyncClient::new()
.get("https://api.example.com/users")
.header("Authorization", "Bearer tok_…")
.send()
.await?;
println!("{}", resp.text()?);Structs§
- Async
Client - Asynchronous HTTP/1.1 client (
http2feature required). - Async
Request Builder - Builder for an async HTTP request.
- Client
- Synchronous HTTP/1.1 client.
- Http
Client Error - Error returned by the HTTP client.
- Request
Builder - Builder for a single HTTP request.
- Response
- HTTP response from the outbound client.