HttpRequest

Trait HttpRequest 

Source
pub trait HttpRequest {
    type Response: FromHttpResponse;
    type Query: HttpRequestQueryParams;
    type Body: HttpRequestBody;

    const METHOD: Method;

    // Required method
    fn path(&self) -> String;

    // Provided methods
    fn query(&self) -> Option<&Self::Query> { ... }
    fn body(&self) -> Option<&Self::Body> { ... }
    fn apply_headers(&self, headers: &mut HeaderMap) { ... }
    fn to_http_request(&self, base_url: &Url) -> Result<Request<Vec<u8>>, Error> { ... }
    fn read_response(response: Response<Bytes>) -> Result<Self::Response, Error> { ... }
}
Expand description

A trait implemented for types that are sent to the API as parameters

Required Associated Constants§

Source

const METHOD: Method

The method used to send the data to the API endpoint

Required Associated Types§

Source

type Response: FromHttpResponse

The response type that is expected to the request

Source

type Query: HttpRequestQueryParams

The query type that is sent to the API endpoint

Source

type Body: HttpRequestBody

The body type that is sent to the API endpoint

Required Methods§

Source

fn path(&self) -> String

Get the API endpoint path relative to the base URL

Provided Methods§

Source

fn query(&self) -> Option<&Self::Query>

Get query parameters for the http::Request

Source

fn body(&self) -> Option<&Self::Body>

Get the body for the http::Request

Source

fn apply_headers(&self, headers: &mut HeaderMap)

Get the headers for the http::Request

Source

fn to_http_request(&self, base_url: &Url) -> Result<Request<Vec<u8>>, Error>

Build a HTTP request from the request type

Source

fn read_response(response: Response<Bytes>) -> Result<Self::Response, Error>

Convert the response from a http::Response

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§