Skip to main content

Builder

Struct Builder 

Source
pub struct Builder {
    pub base_url: String,
    pub proxy: Option<String>,
    pub timeout: Option<Duration>,
    pub headers: HashMap<String, String>,
    pub max_retries: usize,
    pub max_connections: usize,
}
Expand description

Shared configuration for BlockingClient and AsyncClient.

Start with Builder::new and then chain optional configuration methods before calling Builder::build_blocking, Builder::build_async, or Builder::build_async_with_sleeper.

§Example

use std::time::Duration;

let client = esplora_client::Builder::new("https://mempool.space/testnet/api")
    .timeout(Duration::from_secs(30))
    .max_retries(4)
    .header("user-agent", "my-wallet/0.1")
    .build_blocking();

Fields§

§base_url: String

The base URL of the Esplora server.

This should include the API prefix expected by the server, for example https://mempool.space/api or https://blockstream.info/testnet/api.

§proxy: Option<String>

Optional proxy URL used for requests to the Esplora server.

The string should be formatted as: <protocol>://<user>:<password>@host:<port>.

Note that the format of this value and the supported protocols change slightly by target and enabled transport features. See bitreq’s proxy documentation for the accepted schemes.

The proxy is ignored when targeting wasm32.

§timeout: Option<Duration>

Per-request socket timeout.

§headers: HashMap<String, String>

HTTP headers to set on every request made to the Esplora server.

§max_retries: usize

Maximum number of retry attempts for retryable HTTP responses.

§max_connections: usize

Maximum number of cached connections for the async client.

Implementations§

Source§

impl Builder

Source

pub fn new(base_url: &str) -> Self

Create a Builder for an Esplora server base URL.

The URL is stored exactly as provided and request paths are appended to it. Do not include a trailing slash unless your server expects one.

Source

pub fn proxy(self, proxy: &str) -> Self

Set the proxy URL used for requests.

The proxy is ignored when targeting wasm32.

Source

pub fn timeout(self, timeout: Duration) -> Self

Set the per-request socket timeout.

Source

pub fn header(self, key: &str, value: &str) -> Self

Add or replace an HTTP header sent with every request.

Source

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

Set the maximum number of retry attempts for retryable responses.

Only responses whose status code is listed in RETRYABLE_ERROR_CODES are retried.

Source

pub fn max_connections(self, count: usize) -> Self

Set the maximum number of cached connections in the async client.

Source

pub fn build_blocking(self) -> BlockingClient

Build a BlockingClient from this configuration.

Source

pub fn build_async(self) -> Result<AsyncClient, Error>

Build an AsyncClient from this configuration.

This uses DefaultSleeper, which is backed by Tokio.

§Errors

Returns an Error if the async HTTP client cannot be constructed.

Source

pub fn build_async_with_sleeper<S: Sleeper>( self, ) -> Result<AsyncClient<S>, Error>

Build an AsyncClient with a user-defined Sleeper.

Use this when integrating with an async runtime other than Tokio or when tests need a custom sleep implementation.

§Errors

Returns an Error if the async HTTP client cannot be constructed.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

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 Builder

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.