Struct http_typed::Client
source · pub struct Client<RequestGroup = All> { /* private fields */ }
Expand description
A client to delegate to the send function that provides the ability to optionally specify:
- a base url to be used for all requests
- a request group to constrain the request types accepted by this type
Implementations§
source§impl<RequestGroup> Client<RequestGroup>
impl<RequestGroup> Client<RequestGroup>
pub fn new(base_url: String) -> Self
sourcepub async fn send<Req>(
&self,
request: Req
) -> Result<Req::Response, Error<<Req::Serializer as SerializeBody<Req>>::Error>>where
Req: Request + InRequestGroup<RequestGroup>,
Req::Response: for<'a> Deserialize<'a>,
pub async fn send<Req>( &self, request: Req ) -> Result<Req::Response, Error<<Req::Serializer as SerializeBody<Req>>::Error>>where Req: Request + InRequestGroup<RequestGroup>, Req::Response: for<'a> Deserialize<'a>,
Send the provided request to the host at this client’s base_url, using the Request implementation to determine the remaining url path and request data.
The url used for the request is {self.base_url}{request.path()}
sourcepub async fn send_to<Req>(
&self,
url_infix: &str,
request: Req
) -> Result<Req::Response, Error<<Req::Serializer as SerializeBody<Req>>::Error>>where
Req: Request + InRequestGroup<RequestGroup>,
Req::Response: for<'a> Deserialize<'a>,
pub async fn send_to<Req>( &self, url_infix: &str, request: Req ) -> Result<Req::Response, Error<<Req::Serializer as SerializeBody<Req>>::Error>>where Req: Request + InRequestGroup<RequestGroup>, Req::Response: for<'a> Deserialize<'a>,
Send the provided request to the host at this client’s base_url plus url_infix, using the Request implementation to determine the remaining url path and request data.
The url used for the request is {self.base_url}{url_infix}{request.path()}
If you’d like to specify the entire base url for each request using this method, instantiate this struct with base_url = “” (the default)
sourcepub async fn send_custom<Req, Res>(
&self,
path: &str,
method: HttpMethod,
request: Req
) -> Result<Res, Error<Req::Error>>where
Req: SimpleBody,
Res: for<'a> Deserialize<'a>,
pub async fn send_custom<Req, Res>( &self, path: &str, method: HttpMethod, request: Req ) -> Result<Res, Error<Req::Error>>where Req: SimpleBody, Res: for<'a> Deserialize<'a>,
Send the provided request to the specified path using the specified method, and deserialize the response into the specified response type.
The url used for this request is {self.base_url}{path}
If you’d like to specify the entire base url for each request using this method, instantiate this struct with base_url = “” (the default)
Trait Implementations§
source§impl<RequestGroup> Clone for Client<RequestGroup>
impl<RequestGroup> Clone for Client<RequestGroup>
Explicitly implemented to avoid requirement RequestGroup: Clone