pub struct ClientBuilder { /* private fields */ }Expand description
Builder for a Client, giving control over the API key source, base URL,
and request timeout.
The API key may be provided explicitly via api_key
or, if omitted, is read from the DATAMAXI_API_KEY environment variable at
build time.
§Example
use datamaxi::api::ClientBuilder;
use std::time::Duration;
// Explicit key + custom timeout.
let client = ClientBuilder::new()
.api_key("my_api_key")
.timeout(Duration::from_secs(30))
.build()
.expect("api key provided");
// Key taken from the DATAMAXI_API_KEY environment variable.
let client = ClientBuilder::new().build();Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder with default settings (default timeout, no retries,
key read from the environment on build).
Sourcepub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn api_key(self, api_key: impl Into<String>) -> Self
Sets the API key explicitly, overriding the DATAMAXI_API_KEY environment variable.
Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Overrides the base URL (defaults to the production API).
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the per-request timeout (defaults to 10 seconds).
Sourcepub fn max_retries(self, max_retries: u32) -> Self
pub fn max_retries(self, max_retries: u32) -> Self
Sets the maximum number of retries on transient failures (timeouts,
connection errors, 429, and 5xx). Defaults to 0 (no retries);
each retry backs off exponentially from the base delay.
Sourcepub fn retry_base_delay(self, base_delay: Duration) -> Self
pub fn retry_base_delay(self, base_delay: Duration) -> Self
Sets the base delay for exponential retry backoff (defaults to 500ms).
The nth retry waits base_delay * 2^n, capped at 30 seconds.
Sourcepub fn http_client(self, client: Client) -> Self
pub fn http_client(self, client: Client) -> Self
Overrides the internally-built datamaxi::reqwest::Client with a
caller-supplied one — the escape hatch for custom middleware,
timeouts, proxies, or instrumentation (e.g. a reqwest-middleware
client wrapped down to its inner reqwest::Client, or one built with
reqwest_tracing). Use the crate’s re-exported [crate::reqwest] to
build it, so the type always matches without a version mismatch.
When set, ClientBuilder::timeout is ignored for HTTP-level
settings (the caller’s client is used as-is); build
no longer applies the built-in User-Agent / pool defaults.
Trait Implementations§
Source§impl Clone for ClientBuilder
impl Clone for ClientBuilder
Source§fn clone(&self) -> ClientBuilder
fn clone(&self) -> ClientBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more