pub struct PublicRestClient { /* private fields */ }Expand description
Shared unauthenticated HTTP client for exchange public REST endpoints.
Create once and clone cheaply — the underlying reqwest::Client pools
connections across calls.
§Example
use exchange_apiws::http::PublicRestClient;
use serde::Deserialize;
#[derive(Deserialize)]
struct ServerTime { serverTime: u64 }
let client = PublicRestClient::new("https://api.binance.com")?;
let ts: ServerTime = client.get("/api/v3/time", &[]).await?;
println!("Binance server time: {}", ts.serverTime);Implementations§
Source§impl PublicRestClient
impl PublicRestClient
Sourcepub fn new(base_url: impl Into<String>) -> Result<Self>
pub fn new(base_url: impl Into<String>) -> Result<Self>
Build a client pointed at base_url with the default 10 s timeout.
§Errors
Returns ExchangeError::Config if the underlying reqwest client
cannot be built (e.g. TLS initialisation failure).
Sourcepub fn with_timeout(
base_url: impl Into<String>,
timeout: Duration,
) -> Result<Self>
pub fn with_timeout( base_url: impl Into<String>, timeout: Duration, ) -> Result<Self>
Build a client with a caller-specified per-request timeout.
§Errors
Returns ExchangeError::Config if the underlying reqwest client
cannot be built.
Sourcepub async fn get<T: DeserializeOwned>(
&self,
path: &str,
params: &[(&str, &str)],
) -> Result<T>
pub async fn get<T: DeserializeOwned>( &self, path: &str, params: &[(&str, &str)], ) -> Result<T>
Public GET with jittered exponential-backoff retry.
params are percent-encoded and appended as a query string. The
response body is deserialized directly as T with no envelope
unwrapping — the caller is responsible for handling exchange-specific
response shapes (Binance bare JSON, Bybit retCode, etc.).
Retry policy:
- Network errors (connect, timeout, DNS) are retried a few times with jittered exponential backoff.
- HTTP 429 responses honour the
Retry-Afterheader (seconds form). They do not consume the retry budget but are capped at a small fixed count before giving up. - Other 4xx/5xx responses surface as
ExchangeError::Apiwithout retry.
Trait Implementations§
Source§impl Clone for PublicRestClient
impl Clone for PublicRestClient
Source§fn clone(&self) -> PublicRestClient
fn clone(&self) -> PublicRestClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more