Trait http_request_derive::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 Types§
sourcetype Response: FromHttpResponse
type Response: FromHttpResponse
The response type that is expected to the request
sourcetype Query: HttpRequestQueryParams
type Query: HttpRequestQueryParams
The query type that is sent to the API endpoint
sourcetype Body: HttpRequestBody
type Body: HttpRequestBody
The body type that is sent to the API endpoint
Required Associated Constants§
Required Methods§
Provided Methods§
sourcefn apply_headers(&self, headers: &mut HeaderMap)
fn apply_headers(&self, headers: &mut HeaderMap)
Get the headers for the http::Request
sourcefn to_http_request(&self, base_url: &Url) -> Result<Request<Vec<u8>>, Error>
fn to_http_request(&self, base_url: &Url) -> Result<Request<Vec<u8>>, Error>
Build a HTTP request from the request type
sourcefn read_response(response: Response<Bytes>) -> Result<Self::Response, Error>
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.