pub struct Client<ReqBody = Body, RespBody = Body> { /* private fields */ }Available on crate feature
client only.Expand description
An Client for sending HTTP requests and handling HTTP responses.
§Examples
use volo_http::{body::BodyConversion, client::Client};
let client = Client::builder().build().unwrap();
let resp = client
.get("http://httpbin.org/get")
.send()
.await
.expect("failed to send request")
.into_string()
.await
.expect("failed to convert response to string");
println!("{resp:?}");Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder<Identity, Identity, DefaultMkClient, DefaultLb>
pub fn builder() -> ClientBuilder<Identity, Identity, DefaultMkClient, DefaultLb>
Create a new client builder.
Source§impl<ReqBody, RespBody> Client<ReqBody, RespBody>
impl<ReqBody, RespBody> Client<ReqBody, RespBody>
Sourcepub fn request_builder(&self) -> RequestBuilder<Self>
pub fn request_builder(&self) -> RequestBuilder<Self>
Create a builder for building a request.
Sourcepub fn request<U>(&self, method: Method, uri: U) -> RequestBuilder<Self>
pub fn request<U>(&self, method: Method, uri: U) -> RequestBuilder<Self>
Create a builder for building a request with the specified method and URI.
Sourcepub fn options<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn options<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with OPTIONS method and the given uri.
Sourcepub fn get<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn get<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with GET method and the given uri.
Sourcepub fn post<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn post<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with POST method and the given uri.
Sourcepub fn put<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn put<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with PUT method and the given uri.
Sourcepub fn delete<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn delete<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with DELETE method and the given uri.
Sourcepub fn head<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn head<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with HEAD method and the given uri.
Sourcepub fn trace<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn trace<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with TRACE method and the given uri.
Sourcepub fn connect<U>(&self, uri: U) -> RequestBuilder<Self>
pub fn connect<U>(&self, uri: U) -> RequestBuilder<Self>
Create a request with CONNECT method and the given uri.
Trait Implementations§
Source§impl<ReqBody, RespBody> OneShotService<ClientContext, Request<ReqBody>> for Client<ReqBody, RespBody>where
ReqBody: Send,
impl<ReqBody, RespBody> OneShotService<ClientContext, Request<ReqBody>> for Client<ReqBody, RespBody>where
ReqBody: Send,
Source§type Error = ClientError
type Error = ClientError
Errors produced by the service.
Auto Trait Implementations§
impl<ReqBody, RespBody> Freeze for Client<ReqBody, RespBody>
impl<ReqBody, RespBody> RefUnwindSafe for Client<ReqBody, RespBody>
impl<ReqBody, RespBody> Send for Client<ReqBody, RespBody>
impl<ReqBody, RespBody> Sync for Client<ReqBody, RespBody>
impl<ReqBody, RespBody> Unpin for Client<ReqBody, RespBody>
impl<ReqBody, RespBody> UnwindSafe for Client<ReqBody, RespBody>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, Cx, Req> ServiceExt<Cx, Req> for Twhere
T: Service<Cx, Req>,
impl<T, Cx, Req> ServiceExt<Cx, Req> for Twhere
T: Service<Cx, Req>,
Source§fn map_err<E, F>(self, f: F) -> MapErr<T, F>
fn map_err<E, F>(self, f: F) -> MapErr<T, F>
Maps this service’s error value to a different value. Read more
Source§fn map_response<F, Response>(self, f: F) -> MapResponse<T, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<T, F>
Maps this service’s response value to a different value. Read more