macro_rules! http {
($client:expr) => { ... };
($client:expr, label = $label:expr) => { ... };
}Expand description
Wrap an HTTP client so every request it sends is timed and reported in the
http section, keyed by normalized endpoint.
For reqwest::Client this returns the matching reqwest-middleware
ClientWithMiddleware (spelled hotpath::wrap::reqwest::Client for
feature-independent type names). For a ureq ConfigBuilder it returns the
same builder with hotpath’s middleware appended. With the hotpath feature
disabled the argument is returned unchanged.
Optional parameter: label (prefixes every endpoint key).
§Examples
ⓘ
let client = hotpath::http!(reqwest::Client::new());
let client = hotpath::http!(reqwest::Client::new(), label = "github");
// Normal reqwest usage from here on:
let resp = client.get("https://api.example.com/users/1").send().await?;
// ureq: instrument the config builder before building the agent.
let agent: ureq::Agent = hotpath::http!(ureq::Agent::config_builder())
.build()
.new_agent();
let resp = agent.get("https://api.example.com/users/1").call()?;