Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Async HTTP client.

The client manages connection pooling and shared configuration. Create one with Client::new or Client::builder.

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Create a new client with default settings.

Source

pub fn builder() -> ClientBuilder

Create a ClientBuilder for configuring a client.

Source

pub fn get(&self, url: &str) -> Result<RequestBuilder>

Create a GET request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn post(&self, url: &str) -> Result<RequestBuilder>

Create a POST request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn put(&self, url: &str) -> Result<RequestBuilder>

Create a PUT request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn patch(&self, url: &str) -> Result<RequestBuilder>

Create a PATCH request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn delete(&self, url: &str) -> Result<RequestBuilder>

Create a DELETE request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn head(&self, url: &str) -> Result<RequestBuilder>

Create a HEAD request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn options(&self, url: &str) -> Result<RequestBuilder>

Create an OPTIONS request builder for the given URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn request(&self, method: Method, url: &str) -> Result<RequestBuilder>

Create a request builder for the given method and URL.

§Errors

Returns Error::InvalidUrl if url cannot be parsed.

Source

pub fn pool_metrics(&self) -> &PoolMetrics

Returns a reference to the connection pool metrics.

These count logical request-permit waits/cancellations. For connector/protocol observations see Self::transport_metrics.

Source

pub fn transport_metrics(&self) -> &TransportMetrics

Returns a reference to the transport observability counters.

Counts connector events (DNS/connect/TLS attempts) and protocol connections (H3 sessions, 101 upgrades) where observable. Hyper socket-reuse counts are intentionally absent.

Source

pub async fn send_detailed( &self, request: Request, ) -> Result<Response, RequestFailure>

Send a request and return optional structured native failure detail.

The ordinary Error remains unchanged and can be recovered with RequestFailure::into_error. Network classifications are reported only when the selected route exposes typed evidence; callers must not treat an absent subtype as a positive diagnosis.

§Errors

Returns the original request error wrapped in crate::RequestFailure.

Source

pub async fn execute_http_body<B>( &self, request: Request<B>, options: NativeRequestOptions, ) -> Result<Response<NativeResponseBody>>
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync + 'static,

Execute a native http_body::Body using eggfetch’s HTTP/TLS transport engine.

This is the lower-level native embedding API. Request DATA and trailer frames are passed through without flattening. The response is an ordinary http::Response whose opaque crate::NativeResponseBody preserves DATA and trailer frames and holds the logical pool lease until the body reaches EOF, errors, or is dropped.

Native execution does not implicitly apply redirects, logical retries, cookies, authentication, response decompression, or decoded body limits. The request body is one-shot. Built-in proxy, HTTP/3, and protocol-upgrade routes are rejected because their current adapters do not expose the frame-preserving contract.

§Errors

Returns an error for an invalid logical URI, unsupported route, pool or transport failure, or a timeout.

Source

pub async fn execute_http_body_default<B>( &self, request: Request<B>, ) -> Result<Response<NativeResponseBody>>
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync + 'static,

Execute a native body request with default native transport options.

§Errors

Returns the same URI, pool, transport, and timeout errors as Self::execute_http_body.

Source§

impl Client

Source

pub fn native_service(&self) -> NativeHttpService

Create a Tower service for the native frame-preserving HTTP path.

The returned service is configured with NativeRequestOptions::default. Use NativeHttpService::with_options to configure service-instance defaults, or call Client::execute_http_body directly for options that vary by request.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

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 Client

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more