Struct generic_api_client::http::Client
source · pub struct Client { /* private fields */ }
Expand description
Client for communicating with APIs through HTTP/HTTPS.
When making a HTTP request or starting a websocket connection with this client, a handler that implements RequestHandler is required.
Implementations§
source§impl Client
impl Client
sourcepub async fn request<Q, B, H>(
&self,
method: Method,
url: &str,
query: Option<&Q>,
body: Option<B>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
pub async fn request<Q, B, H>( &self, method: Method, url: &str, query: Option<&Q>, body: Option<B>, handler: &H ) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
Makes an HTTP request with the given RequestHandler and returns the response.
It is recommended to use methods like get() because this method takes many type parameters and parameters.
The request is passed to handler
before being sent, and the response is passed to handler
before being returned.
Note, that as stated in the docs for RequestBuilder::query(), parameter query
only accepts a sequence of key-value pairs.
sourcepub async fn get<Q, H>(
&self,
url: &str,
query: Option<&Q>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
pub async fn get<Q, H>( &self, url: &str, query: Option<&Q>, handler: &H ) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
Makes an GET request with the given RequestHandler.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().
sourcepub async fn get_no_query<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
pub async fn get_no_query<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
Makes an GET request with the given RequestHandler, without queries.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().
sourcepub async fn post<B, H>(
&self,
url: &str,
body: Option<B>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<B>,
pub async fn post<B, H>(
&self,
url: &str,
body: Option<B>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<B>,
Makes an POST request with the given RequestHandler.
This method just calls request(). It requires less typing for type parameters and parameters.
For more information, see request().
sourcepub async fn post_no_body<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
pub async fn post_no_body<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
Makes an POST request with the given RequestHandler, without a body.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().
sourcepub async fn put<B, H>(
&self,
url: &str,
body: Option<B>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<B>,
pub async fn put<B, H>(
&self,
url: &str,
body: Option<B>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<B>,
Makes an PUT request with the given RequestHandler.
This method just calls request(). It requires less typing for type parameters and parameters.
For more information, see request().
sourcepub async fn put_no_body<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
pub async fn put_no_body<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
Makes an PUT request with the given RequestHandler, without a body.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().
sourcepub async fn delete<Q, H>(
&self,
url: &str,
query: Option<&Q>,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
pub async fn delete<Q, H>( &self, url: &str, query: Option<&Q>, handler: &H ) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
Makes an DELETE request with the given RequestHandler.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().
sourcepub async fn delete_no_query<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
pub async fn delete_no_query<H>(
&self,
url: &str,
handler: &H
) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where
H: RequestHandler<()>,
Makes an DELETE request with the given RequestHandler, without queries.
This method just calls request(). It requires less typing for type parameters and parameters.
This method requires that handler
can handle a request with a body of type ()
. The actual body passed will be None
.
For more information, see request().