pub struct RequestClient<E> { /* private fields */ }
Implementations§
Source§impl<E: From<Error> + From<Error>> RequestClient<E>
impl<E: From<Error> + From<Error>> RequestClient<E>
Sourcepub fn new(
transport: Transport,
validate_fn: Box<ValidateResponseFn<E>>,
) -> Self
pub fn new( transport: Transport, validate_fn: Box<ValidateResponseFn<E>>, ) -> Self
Creates a new RequestClient with a specified transport and a function to validate each response.
Sourcepub async fn get(&self, endpoint: impl AsRef<str>) -> Result<Response<Body>, E>
pub async fn get(&self, endpoint: impl AsRef<str>) -> Result<Response<Body>, E>
Make a GET request to the endpoint
and return the response.
Sourcepub async fn get_string(&self, endpoint: impl AsRef<str>) -> Result<String, E>
pub async fn get_string(&self, endpoint: impl AsRef<str>) -> Result<String, E>
Make a GET request to the endpoint
and return the response as a string.
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
endpoint: impl AsRef<str>,
) -> Result<T, E>
pub async fn get_json<T: DeserializeOwned>( &self, endpoint: impl AsRef<str>, ) -> Result<T, E>
Make a GET request to the endpoint
and return the response as a JSON deserialized object.
Sourcepub fn get_stream<'client>(
&'client self,
endpoint: impl AsRef<str> + 'client,
) -> impl Stream<Item = Result<Bytes, E>> + 'client
pub fn get_stream<'client>( &'client self, endpoint: impl AsRef<str> + 'client, ) -> impl Stream<Item = Result<Bytes, E>> + 'client
Make a GET request to the endpoint
and return a stream of byte chunks.
Sourcepub fn get_json_stream<'client, T>(
&'client self,
endpoint: impl AsRef<str> + 'client,
) -> impl Stream<Item = Result<T, E>> + 'clientwhere
T: DeserializeOwned,
pub fn get_json_stream<'client, T>(
&'client self,
endpoint: impl AsRef<str> + 'client,
) -> impl Stream<Item = Result<T, E>> + 'clientwhere
T: DeserializeOwned,
Make a GET request to the endpoint
and return a stream of JSON chunk results.
Sourcepub async fn post<B>(
&self,
endpoint: impl AsRef<str>,
body: Payload<B>,
headers: Option<Headers>,
) -> Result<Response<Body>, E>
pub async fn post<B>( &self, endpoint: impl AsRef<str>, body: Payload<B>, headers: Option<Headers>, ) -> Result<Response<Body>, E>
Make a POST request to the endpoint
and return the response.
Sourcepub async fn post_string<B>(
&self,
endpoint: impl AsRef<str>,
body: Payload<B>,
headers: Option<Headers>,
) -> Result<String, E>
pub async fn post_string<B>( &self, endpoint: impl AsRef<str>, body: Payload<B>, headers: Option<Headers>, ) -> Result<String, E>
Make a POST request to the endpoint
and return the response as a string.
Sourcepub async fn post_json<B, T>(
&self,
endpoint: impl AsRef<str>,
body: Payload<B>,
headers: Option<Headers>,
) -> Result<T, E>
pub async fn post_json<B, T>( &self, endpoint: impl AsRef<str>, body: Payload<B>, headers: Option<Headers>, ) -> Result<T, E>
Make a POST request to the endpoint
and return the response as a JSON
deserialized value.
Sourcepub fn post_stream<'client, B>(
&'client self,
endpoint: impl AsRef<str> + 'client,
body: Payload<B>,
headers: Option<Headers>,
) -> impl Stream<Item = Result<Bytes, E>> + 'client
pub fn post_stream<'client, B>( &'client self, endpoint: impl AsRef<str> + 'client, body: Payload<B>, headers: Option<Headers>, ) -> impl Stream<Item = Result<Bytes, E>> + 'client
Make a straeming POST request to the endpoint
and return a
stream of byte chunks.
Use post_into_stream
if the endpoint
returns JSON values.
Sourcepub fn post_into_stream<'client, B, T>(
&'client self,
endpoint: impl AsRef<str> + 'client,
body: Payload<B>,
headers: Option<Headers>,
) -> impl Stream<Item = Result<T, E>> + 'client
pub fn post_into_stream<'client, B, T>( &'client self, endpoint: impl AsRef<str> + 'client, body: Payload<B>, headers: Option<Headers>, ) -> impl Stream<Item = Result<T, E>> + 'client
Make a streaming POST request to the endpoint
and return a stream of
JSON deserialized chunks.
pub async fn post_upgrade_stream<B>( self, endpoint: impl AsRef<str>, body: Payload<B>, ) -> Result<impl AsyncRead + AsyncWrite, E>
Sourcepub async fn put<B>(
&self,
endpoint: impl AsRef<str>,
body: Payload<B>,
) -> Result<Response<Body>, E>
pub async fn put<B>( &self, endpoint: impl AsRef<str>, body: Payload<B>, ) -> Result<Response<Body>, E>
Make a PUT request to the endpoint
and return the response.
Sourcepub async fn put_string<B>(
&self,
endpoint: impl AsRef<str>,
body: Payload<B>,
) -> Result<String, E>
pub async fn put_string<B>( &self, endpoint: impl AsRef<str>, body: Payload<B>, ) -> Result<String, E>
Make a PUT request to the endpoint
and return the response as a string.
Sourcepub async fn delete(
&self,
endpoint: impl AsRef<str>,
) -> Result<Response<Body>, E>
pub async fn delete( &self, endpoint: impl AsRef<str>, ) -> Result<Response<Body>, E>
Make a DELETE request to the endpoint
and return the response.
Sourcepub async fn delete_string(
&self,
endpoint: impl AsRef<str>,
) -> Result<String, E>
pub async fn delete_string( &self, endpoint: impl AsRef<str>, ) -> Result<String, E>
Make a DELETE request to the endpoint
and return the response as a string.
Sourcepub async fn delete_json<T: DeserializeOwned>(
&self,
endpoint: impl AsRef<str>,
) -> Result<T, E>
pub async fn delete_json<T: DeserializeOwned>( &self, endpoint: impl AsRef<str>, ) -> Result<T, E>
Make a DELETE request to the endpoint
and return the response as a JSON
deserialized object.
Trait Implementations§
Source§impl<E: Clone> Clone for RequestClient<E>
impl<E: Clone> Clone for RequestClient<E>
Source§fn clone(&self) -> RequestClient<E>
fn clone(&self) -> RequestClient<E>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more