pub struct HttpClient { /* private fields */ }Expand description
HTTP client with retry and rate limiting support
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: HttpConfig) -> Result<Self>
pub fn new(config: HttpConfig) -> Result<Self>
Sourcepub fn new_with_rate_limiter(
config: HttpConfig,
rate_limiter: RateLimiter,
) -> Result<Self>
pub fn new_with_rate_limiter( config: HttpConfig, rate_limiter: RateLimiter, ) -> Result<Self>
Sourcepub fn set_rate_limiter(&mut self, rate_limiter: RateLimiter)
pub fn set_rate_limiter(&mut self, rate_limiter: RateLimiter)
Sourcepub fn set_retry_strategy(&mut self, strategy: RetryStrategy)
pub fn set_retry_strategy(&mut self, strategy: RetryStrategy)
Sets the retry strategy for this client.
§Arguments
strategy- Retry strategy to use for failed requests
Sourcepub async fn fetch(
&self,
url: &str,
method: Method,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn fetch( &self, url: &str, method: Method, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Executes an HTTP request with automatic retry mechanism.
§Arguments
url- Target URL for the requestmethod- HTTP method to useheaders- Optional custom headersbody- Optional request body as JSON
§Returns
Returns the response body as a JSON Value.
§Errors
Returns an error if:
- All retry attempts fail
- The server returns an error status code
- Network communication fails
Sourcepub async fn post(
&self,
url: &str,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn post( &self, url: &str, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Sourcepub async fn put(
&self,
url: &str,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn put( &self, url: &str, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Sourcepub async fn delete(
&self,
url: &str,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn delete( &self, url: &str, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Sourcepub fn config(&self) -> &HttpConfig
pub fn config(&self) -> &HttpConfig
Returns a reference to the current HTTP configuration.
Sourcepub fn set_config(&mut self, config: HttpConfig)
pub fn set_config(&mut self, config: HttpConfig)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more