pub struct ClientBuilder { /* private fields */ }Expand description
Builder for constructing a Client with custom configuration.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with defaults (30s timeout, 3 retries, exponential backoff).
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
pub fn base_url(self, url: impl Into<String>) -> Self
Set a base URL that is prepended to all relative paths.
Sourcepub fn retries(self, retries: u32) -> Self
pub fn retries(self, retries: u32) -> Self
Set the maximum number of retries.
Shapes the built-in middleware::RetryMiddleware (feature
retry, default-on). For custom retry behavior, register a
middleware::RetryMiddleware with a full
middleware::RetryConfig via ClientBuilder::with_middleware.
Sourcepub fn retry_bounds(self, initial: Duration, max: Duration) -> Self
pub fn retry_bounds(self, initial: Duration, max: Duration) -> Self
Set the initial and maximum retry backoff durations.
Sourcepub fn with_middleware(self, middleware: impl Middleware) -> Self
pub fn with_middleware(self, middleware: impl Middleware) -> Self
Register custom middleware to run outermost — wrapping the built-in retry/breaker stack — observing each logical request once.
Middleware registered first runs outermost; see the
middleware module docs for the full ordering semantics.
Sourcepub fn default_header(self, key: &'static str, value: &'static str) -> Self
pub fn default_header(self, key: &'static str, value: &'static str) -> Self
Add a default header applied to every request (infallible for compile-time string literals).
§Panics
Panics if key or value is not a valid HTTP header string —
this is a caller programming error, not a runtime condition.
Use default_headers with a HeaderMap
for a fallible variant.
Sourcepub fn default_headers(self, headers: HeaderMap) -> Self
pub fn default_headers(self, headers: HeaderMap) -> Self
Set multiple default headers applied to every request.
Sourcepub fn user_agent(self, agent: &'static str) -> Self
pub fn user_agent(self, agent: &'static str) -> Self
Set the User-Agent header.
Sourcepub fn reqwest_builder(self, builder: ClientBuilder) -> Self
pub fn reqwest_builder(self, builder: ClientBuilder) -> Self
Add a raw reqwest::ClientBuilder for advanced configuration.
Sourcepub fn try_build(self) -> Result<Client, FetchError>
pub fn try_build(self) -> Result<Client, FetchError>
Build the Client, returning a FetchError on failure.