pub struct Client { /* private fields */ }Expand description
A resilient HTTP client with retry, timeout, and typed JSON support.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start building a client with custom settings.
Sourcepub fn from_parts(inner: ClientWithMiddleware, base_url: Option<String>) -> Self
pub fn from_parts(inner: ClientWithMiddleware, base_url: Option<String>) -> Self
Construct a Client from a pre-built ClientWithMiddleware and
an optional base URL.
This is useful when you need to attach custom middleware (e.g. a
circuit breaker from an external registry) that fetch_kit’s builder
does not natively support. Use Client::with_middleware to append
further middleware to the chain after construction.
Sourcepub fn with_middleware(self, middleware: impl Middleware) -> Self
pub fn with_middleware(self, middleware: impl Middleware) -> Self
Append a middleware inside the existing chain (closest to the transport) and return the new client.
This is a composition point for already-built clients. When
building from scratch, prefer ClientBuilder::with_middleware,
which registers middleware outermost.
Sourcepub fn get(&self, url: impl Into<String>) -> RequestBuilder<'_>
pub fn get(&self, url: impl Into<String>) -> RequestBuilder<'_>
Create a RequestBuilder for a GET request.
Sourcepub fn post(&self, url: impl Into<String>) -> RequestBuilder<'_>
pub fn post(&self, url: impl Into<String>) -> RequestBuilder<'_>
Create a RequestBuilder for a POST request.
Sourcepub fn put(&self, url: impl Into<String>) -> RequestBuilder<'_>
pub fn put(&self, url: impl Into<String>) -> RequestBuilder<'_>
Create a RequestBuilder for a PUT request.
Sourcepub fn delete(&self, url: impl Into<String>) -> RequestBuilder<'_>
pub fn delete(&self, url: impl Into<String>) -> RequestBuilder<'_>
Create a RequestBuilder for a DELETE request.
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
url: &str,
) -> Result<T, FetchError>
pub async fn get_json<T: DeserializeOwned>( &self, url: &str, ) -> Result<T, FetchError>
Perform a GET request and deserialize the JSON response (requires
the json feature).
Sourcepub async fn post_json<B: Serialize, T: DeserializeOwned>(
&self,
url: &str,
body: &B,
) -> Result<T, FetchError>
pub async fn post_json<B: Serialize, T: DeserializeOwned>( &self, url: &str, body: &B, ) -> Result<T, FetchError>
Perform a POST request with a JSON body and deserialize the JSON response (requires
the json feature).
Sourcepub async fn fetch_with_fallback<T: DeserializeOwned>(
&self,
primary_url: &str,
fallback_url: &str,
) -> Result<T, FetchError>
pub async fn fetch_with_fallback<T: DeserializeOwned>( &self, primary_url: &str, fallback_url: &str, ) -> Result<T, FetchError>
Fetch from primary_url; on failure, fall back to fallback_url (requires
the json feature).
Sourcepub fn inner(&self) -> &ClientWithMiddleware
pub fn inner(&self) -> &ClientWithMiddleware
Access the inner middleware::ClientWithMiddleware.
The returned client shares this client’s connection pool and
middleware chain; use middleware::ClientWithMiddleware::with_middleware
(or Client::with_middleware) to compose further middleware onto it.