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§
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 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.
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.