Struct restson::RestClient

source ·
pub struct RestClient { /* private fields */ }
Expand description

REST client to make HTTP GET and POST requests.

Implementations§

source§

impl RestClient

source

pub fn new(url: &str) -> Result<RestClient, Error>

Construct new client with default configuration to make HTTP requests.

Use Builder to configure the client.

source

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.

source

pub fn builder() -> Builder

Configure a client

source

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

source

pub fn set_auth(&mut self, user: &str, pass: &str)

Set credentials for HTTP Basic authentication.

source

pub fn set_body_wash_fn(&mut self, func: fn(_: String) -> String)

Set a function that cleans the response body up before deserializing it.

source

pub fn set_timeout(&mut self, timeout: Duration)

Set request timeout

source

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.

source

pub fn clear_headers(&mut self)

Clear all previously set headers

source

pub async fn get<U, T>(&self, params: U) -> Result<Response<T>, Error>where T: DeserializeOwned + RestPath<U>,

Make a GET request.

source

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.

source

pub async fn post<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make a POST request.

source

pub async fn put<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make a PUT request.

source

pub async fn patch<U, T>( &self, params: U, data: &T ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make a PATCH request.

source

pub async fn post_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make POST request with query parameters.

source

pub async fn put_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make PUT request with query parameters.

source

pub async fn patch_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make PATCH request with query parameters.

source

pub async fn post_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a POST request and capture returned body.

source

pub async fn put_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a PUT request and capture returned body.

source

pub async fn patch_capture<U, T, K>( &self, params: U, data: &T ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a PATCH request and capture returned body.

source

pub async fn post_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a POST request with query parameters and capture returned body.

source

pub async fn put_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a PUT request with query parameters and capture returned body.

source

pub async fn patch_capture_with<U, T, K>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<K>, Error>where T: Serialize + RestPath<U>, K: DeserializeOwned,

Make a PATCH request with query parameters and capture returned body.

source

pub async fn delete<U, T>(&self, params: U) -> Result<Response<()>, Error>where T: RestPath<U>,

Make a DELETE request.

source

pub async fn delete_with<U, T>( &self, params: U, data: &T, query: &Query<'_> ) -> Result<Response<()>, Error>where T: Serialize + RestPath<U>,

Make a DELETE request with query and body.

Trait Implementations§

source§

impl TryFrom<RestClient> for RestClient

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(other: AsyncRestClient) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more