pub struct HttpClientBuilder { /* private fields */ }Expand description
Builder for configuring HTTP clients.
Provides a consistent way to configure HTTP clients across all API crates with sensible defaults.
§Example
use polyoxide_core::HttpClientBuilder;
let client = HttpClientBuilder::new("https://api.example.com")
.timeout_ms(60_000)
.pool_size(20)
.build()
.unwrap();Implementations§
Source§impl HttpClientBuilder
impl HttpClientBuilder
Sourcepub fn new(base_url: impl Into<String>) -> Self
pub fn new(base_url: impl Into<String>) -> Self
Create a new HTTP client builder with the given base URL.
Sourcepub fn timeout_ms(self, timeout: u64) -> Self
pub fn timeout_ms(self, timeout: u64) -> Self
Set request timeout in milliseconds.
Default: 30,000ms (30 seconds)
Sourcepub fn pool_size(self, size: usize) -> Self
pub fn pool_size(self, size: usize) -> Self
Set connection pool size per host.
Default: 10 connections
Sourcepub fn with_rate_limiter(self, limiter: RateLimiter) -> Self
pub fn with_rate_limiter(self, limiter: RateLimiter) -> Self
Set a rate limiter for this client: with_throttle
with a RateLimiter.
Sourcepub fn with_throttle(self, throttle: impl Throttle + 'static) -> Self
pub fn with_throttle(self, throttle: impl Throttle + 'static) -> Self
Set the throttle every request on this client goes through, shared
with every with_base_url sibling.
Default: NoThrottle, which charges and holds
nothing.
Sourcepub fn with_retry_policy(self, policy: impl RetryPolicy + 'static) -> Self
pub fn with_retry_policy(self, policy: impl RetryPolicy + 'static) -> Self
Set the policy that decides what follows each response.
Default: DefaultRetryPolicy, which
retries a 429 and nothing else.
Sourcepub fn with_retry_config(self, config: RetryConfig) -> Self
pub fn with_retry_config(self, config: RetryConfig) -> Self
Set the retry schedule: how many retries, and the backoff between them.
Sourcepub fn with_max_concurrent(self, max: usize) -> Self
pub fn with_max_concurrent(self, max: usize) -> Self
Set the maximum number of concurrent in-flight HTTP requests.
Prevents Cloudflare 1015 rate-limit errors caused by request bursts when many callers share the same client concurrently.
Sourcepub fn runtime(self, runtime: Arc<dyn Runtime>) -> Self
pub fn runtime(self, runtime: Arc<dyn Runtime>) -> Self
Set the runtime this client’s waits, clock reads and spawns go
through, shared with every with_base_url
sibling.
Default: polyoxide_rt::default_runtime. A throttle installed with
with_throttle keeps time on the runtime it was
built on: build it on this one, as the venue crates do.
Sourcepub fn gzip(self, enabled: bool) -> Self
pub fn gzip(self, enabled: bool) -> Self
Ask for gzip-compressed responses and decode them, or pin that off.
Unset by default, which leaves reqwest’s own default. This crate enables
reqwest’s gzip feature, so an unset client asks for gzip and decodes
the body transparently, as every client did for a consumer whose
workspace enabled the feature before this setting existed. 0.37.0 set
it off unless asked, which took compression away from those consumers.
Sourcepub fn http_transport(self, transport: Arc<dyn HttpTransport>) -> Self
pub fn http_transport(self, transport: Arc<dyn HttpTransport>) -> Self
Send every attempt on transport instead of the target’s default,
shared with every with_base_url sibling.
The builder’s timeout still travels with each request, as its
HttpRequest::timeout, but pool_size and
gzip feed only the default ReqwestTransport: a
transport you inject owns its own connections and compression.
Sourcepub fn build(self) -> Result<HttpClient, ApiError>
pub fn build(self) -> Result<HttpClient, ApiError>
Build the HTTP client.