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

source

pub fn new() -> Self

Constructs a new Client.

source

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>>where Q: Serialize + ?Sized, H: RequestHandler<B>,

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.

source

pub async fn get<Q, H>( &self, url: &str, query: Option<&Q>, handler: &H ) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where Q: Serialize + ?Sized, H: RequestHandler<()>,

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().

source

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().

source

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().

source

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().

source

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().

source

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().

source

pub async fn delete<Q, H>( &self, url: &str, query: Option<&Q>, handler: &H ) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>where Q: Serialize + ?Sized, H: RequestHandler<()>,

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().

source

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().

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Client

source§

fn default() -> Client

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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