Struct restson::RestClient
source · pub struct RestClient { /* private fields */ }
Expand description
REST client to make HTTP GET and POST requests.
Implementations§
source§impl RestClient
impl RestClient
sourcepub fn new(url: &str) -> Result<RestClient, Error>
pub fn new(url: &str) -> Result<RestClient, Error>
Construct new client with default configuration to make HTTP requests.
Use Builder
to configure the client.
sourcepub fn new_blocking(url: &str) -> Result<RestClient, Error>
pub fn new_blocking(url: &str) -> Result<RestClient, Error>
Construct new blocking client with default configuration to make HTTP requests.
Use Builder
to configure the client.
sourcepub fn set_send_null_body(&mut self, send_null: bool)
pub fn set_send_null_body(&mut self, send_null: bool)
Set whether a message body consisting only ‘null’ (from serde serialization) is sent in POST/PUT
sourcepub fn set_auth(&mut self, user: &str, pass: &str)
pub fn set_auth(&mut self, user: &str, pass: &str)
Set credentials for HTTP Basic authentication.
sourcepub fn set_body_wash_fn(&mut self, func: fn(_: String) -> String)
pub fn set_body_wash_fn(&mut self, func: fn(_: String) -> String)
Set a function that cleans the response body up before deserializing it.
sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Set request timeout
sourcepub fn set_header(
&mut self,
name: &'static str,
value: &str
) -> Result<(), Error>
pub fn set_header( &mut self, name: &'static str, value: &str ) -> Result<(), Error>
Set HTTP header from string name and value.
The header is added to all subsequent GET and POST requests
unless the headers are cleared with clear_headers()
call.
sourcepub fn clear_headers(&mut self)
pub fn clear_headers(&mut self)
Clear all previously set headers
sourcepub async fn get<U, T>(&self, params: U) -> Result<Response<T>, Error>where
T: DeserializeOwned + RestPath<U>,
pub async fn get<U, T>(&self, params: U) -> Result<Response<T>, Error>where
T: DeserializeOwned + RestPath<U>,
Make a GET request.
sourcepub async fn get_with<U, T>(
&self,
params: U,
query: &Query<'_>
) -> Result<Response<T>, Error>where
T: DeserializeOwned + RestPath<U>,
pub async fn get_with<U, T>(
&self,
params: U,
query: &Query<'_>
) -> Result<Response<T>, Error>where
T: DeserializeOwned + RestPath<U>,
Make a GET request with query parameters.
sourcepub async fn post<U, T>(
&self,
params: U,
data: &T
) -> Result<Response<()>, Error>
pub async fn post<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>
Make a POST request.
sourcepub async fn put<U, T>(
&self,
params: U,
data: &T
) -> Result<Response<()>, Error>
pub async fn put<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>
Make a PUT request.
sourcepub async fn patch<U, T>(
&self,
params: U,
data: &T
) -> Result<Response<()>, Error>
pub async fn patch<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>
Make a PATCH request.
sourcepub async fn post_with<U, T>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<()>, Error>
pub async fn post_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>
Make POST request with query parameters.
sourcepub async fn put_with<U, T>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<()>, Error>
pub async fn put_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>
Make PUT request with query parameters.
sourcepub async fn patch_with<U, T>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<()>, Error>
pub async fn patch_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>
Make PATCH request with query parameters.
sourcepub async fn post_capture<U, T, K>(
&self,
params: U,
data: &T
) -> Result<Response<K>, Error>
pub async fn post_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>
Make a POST request and capture returned body.
sourcepub async fn put_capture<U, T, K>(
&self,
params: U,
data: &T
) -> Result<Response<K>, Error>
pub async fn put_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>
Make a PUT request and capture returned body.
sourcepub async fn patch_capture<U, T, K>(
&self,
params: U,
data: &T
) -> Result<Response<K>, Error>
pub async fn patch_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>
Make a PATCH request and capture returned body.
sourcepub async fn delete_capture<U, T, K>(
&self,
params: U,
data: &T
) -> Result<Response<K>, Error>
pub async fn delete_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>
Make a DELETE request and capture returned body.
sourcepub async fn post_capture_with<U, T, K>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<K>, Error>
pub async fn post_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>
Make a POST request with query parameters and capture returned body.
sourcepub async fn put_capture_with<U, T, K>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<K>, Error>
pub async fn put_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>
Make a PUT request with query parameters and capture returned body.
sourcepub async fn patch_capture_with<U, T, K>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<K>, Error>
pub async fn patch_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>
Make a PATCH request with query parameters and capture returned body.
sourcepub async fn delete_capture_with<U, T, K>(
&self,
params: U,
data: &T,
query: &Query<'_>
) -> Result<Response<K>, Error>
pub async fn delete_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>
Make a DELETE request with query parameters and capture returned body.