Skip to main content

HttpClientBuilder

Struct HttpClientBuilder 

Source
pub struct HttpClientBuilder { /* private fields */ }
Expand description

Fluent builder for constructing a reusable HttpClient.

Implementations§

Source§

impl HttpClientBuilder

Inherent implementation of HttpClientBuilder.

Source

pub fn new() -> Self

Creates a new HttpClientBuilder with keep-alive enabled by default.

§Returns
  • Self - Fresh client builder.
Source

pub fn base_url<T>(self, url: T) -> Self
where T: Into<String>,

Configures a base URL prepended to relative paths passed to HttpClient request methods.

§Arguments
  • T - Base URL such as "https://api.example.com" or "http://127.0.0.1:8080/v1".
§Returns
  • Self - Updated client builder.
Source

pub fn default_header<K, V>(self, key: K, value: V) -> Self
where K: AsRef<str>, V: AsRef<str>,

Adds a default header automatically included on every request created by this client.

§Arguments
  • K - Header name (normalized to lowercase).
  • V - Header value.
§Returns
  • Self - Updated client builder.
Source

pub fn bearer_auth<T>(self, token: T) -> Self
where T: AsRef<str>,

Configures a default Authorization: Bearer <token> header for every request.

§Arguments
  • T - Bearer token string.
§Returns
  • Self - Updated client builder.
Source

pub fn basic_auth<U, P>(self, username: U, password: P) -> Self
where U: AsRef<str>, P: AsRef<str>,

Configures a default Authorization: Basic <credentials> header for every request.

§Arguments
  • U - Username string.
  • P - Password string.
§Returns
  • Self - Updated client builder.
Source

pub fn timeout(self, ms: u64) -> Self

Sets the default request timeout in milliseconds.

§Arguments
  • u64 - Timeout in milliseconds (0 disables timeout).
§Returns
  • Self - Updated client builder.
Source

pub fn connect_timeout(self, ms: u64) -> Self

Sets the default TCP connect timeout in milliseconds (0 inherits timeout).

§Arguments
  • u64 - Connect timeout in milliseconds.
§Returns
  • Self - Updated client builder.
Source

pub fn retry(self, max_retries: usize) -> Self

Sets the default bounded retry count for idempotent transient failures.

§Arguments
  • usize - Maximum retry attempts (0 disables retries).
§Returns
  • Self - Updated client builder.
Source

pub fn keep_alive(self, enabled: bool) -> Self

Enables or disables persistent HTTP keep-alive connection pooling.

§Arguments
  • bool - true to pool persistent connections (default), false to close after each request.
§Returns
  • Self - Updated client builder.
Source

pub fn http1_1_only(self) -> Self

Forces HTTP/1.1 for all requests built by this client.

§Returns
  • Self - Updated client builder.
Source

pub fn http2_only(self) -> Self

Forces HTTP/2 for all requests built by this client.

§Returns
  • Self - Updated client builder.
Source

pub fn redirect(self, max_redirects: usize) -> Self

Enables automatic 3xx redirect following with up to max_redirects hops.

§Arguments
  • usize - Maximum number of redirects to follow.
§Returns
  • Self - Updated client builder.
Source

pub fn no_redirect(self) -> Self

Disables automatic 3xx redirect following.

§Returns
  • Self - Updated client builder.
Source

pub fn decode(self, enabled: bool) -> Self

Enables or disables automatic response body decompression (gzip/deflate/br).

§Arguments
  • bool - true to automatically decode compressed response bodies.
§Returns
  • Self - Updated client builder.
Source

pub fn proxy(self, proxy: Proxy) -> Self

Configures a proxy for all requests built by this client.

§Arguments
  • Proxy - Proxy configuration.
§Returns
  • Self - Updated client builder.
Source

pub fn root_cert_pem(self, pem_bytes: &[u8]) -> Result<Self, RequestError>

Adds one or more PEM-encoded custom root CA certificates shared across all requests from this client.

§Arguments
  • &[u8] - Raw PEM-encoded X.509 certificate bytes.
§Returns
  • Result<Self, RequestError> - Updated builder or an error on invalid PEM input.
Source

pub fn build(self) -> HttpClient

Finalizes the builder into a reusable, cheaply cloneable HttpClient.

§Returns
  • HttpClient - Constructed client instance.

Trait Implementations§

Source§

impl Clone for HttpClientBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HttpClientBuilder

Default construction for HttpClientBuilder.

Source§

fn default() -> Self

Creates an HttpClientBuilder with persistent keep-alive pooling enabled by default.

§Returns
  • Self - Default client builder with keep_alive = true.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more