Trait Request

Source
pub trait Request: Send {
    type Data: Serialize;
    type Response: for<'de> Deserialize<'de>;

    const METHOD: Method = Method::GET;

    // Required method
    fn endpoint(&self) -> Cow<'_, str>;

    // Provided methods
    fn headers(&self) -> HeaderMap { ... }
    fn data(&self) -> RequestData<&Self::Data> { ... }
}
Expand description

The base-trait for requests sent by the client. The trait specifies the full life-cycle of the request, including the endpoint, headers, data, method and eventual response.

Provided Associated Constants§

Source

const METHOD: Method = Method::GET

The HTTP method for the request.

Required Associated Types§

Source

type Data: Serialize

The type of additional data sent with the request. Usually, this will be () or Self.

Source

type Response: for<'de> Deserialize<'de>

The type of the response from the server.

Required Methods§

Source

fn endpoint(&self) -> Cow<'_, str>

The endpoint to which the request will be sent. The base url is set in the client, and the endpoint method returns the specific resource endpoint.

Provided Methods§

Source

fn headers(&self) -> HeaderMap

Any additional headers that should be sent with the request. Note that common headers such as authorization headers should be set on the client directly.

Source

fn data(&self) -> RequestData<&Self::Data>

The formatted request data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§