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: StringThe 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: usizeMaximum number of retry attempts for retryable HTTP responses.
max_connections: usizeMaximum number of cached connections for the async client.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(base_url: &str) -> Self
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.
Sourcepub fn proxy(self, proxy: &str) -> Self
pub fn proxy(self, proxy: &str) -> Self
Set the proxy URL used for requests.
The proxy is ignored when targeting wasm32.
Sourcepub fn header(self, key: &str, value: &str) -> Self
pub fn header(self, key: &str, value: &str) -> Self
Add or replace an HTTP header sent with every request.
Sourcepub fn max_retries(self, count: usize) -> Self
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.
Sourcepub fn max_connections(self, count: usize) -> Self
pub fn max_connections(self, count: usize) -> Self
Set the maximum number of cached connections in the async client.
Sourcepub fn build_blocking(self) -> BlockingClient
pub fn build_blocking(self) -> BlockingClient
Build a BlockingClient from this configuration.
Sourcepub fn build_async(self) -> Result<AsyncClient, Error>
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.
Sourcepub fn build_async_with_sleeper<S: Sleeper>(
self,
) -> Result<AsyncClient<S>, Error>
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.