HTTP client

feature: client client-tls for HTTPS

Enable

churust = { version = "0.3", features = ["client"] }
# HTTPS:
churust = { version = "0.3", features = ["client-tls"] }

Overview

Outbound client built on the same hyper stack as the server: pooled, bounded, with transparent gzip/deflate decode and a decompression-bomb ceiling.

#![allow(unused)]
fn main() {
use churust::client::Client; // path may be re-exported via prelude when feature is on

let client = Client::new()
    .timeout(std::time::Duration::from_secs(10))
    .user_agent("my-app/0.1")?;

let res = client
    .get("https://httpbin.org/get")
    .header("x-request-id", "demo")
    .send()
    .await?;

println!("{} {}", res.status(), res.text()?);
}

Builder highlights

MethodPurpose
.timeout(d)Overall / request timeout
.max_response_bytes(n)Response size cap
.max_redirects(n)Redirect limit
.auto_decompress(bool)Transparent decode
.default_header / .user_agentDefaults for all requests

Request builder

#![allow(unused)]
fn main() {
client.post("https://api.example.com/items")
    .bearer(token)
    .json(&payload)
    .send()
    .await?;
}

Also: .query, .form, .body, .put, .patch, .delete, .head.

API reference