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 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 Associated Constants§

source

const METHOD: Method

The method used to send the data 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

§Errors

Usually HTTP response codes that don’t indicate success will be converted to the corresponding Error. For example, a StatusCode::UNAUTHORIZED is converted to Error::Unauthorized. This is the behavior found in the default implementation and can be overwritten by a specialized implementation if required.

Object Safety§

This trait is not object safe.

Implementors§