pub trait HttpCall: Sized {
type Payload: Serialize + DeserializeOwned;
type Response: Serialize + DeserializeOwned;
const ROUTE: Route;
const PAYLOAD: PayloadKind;
// Required methods
fn payload(&self) -> &Self::Payload;
fn from_parts(
params: &PathParams,
payload: Self::Payload,
) -> Result<Self, ApiError>;
// Provided methods
fn path_params(&self) -> PathParams { ... }
fn path(&self) -> Option<String> { ... }
}Expand description
A typed HTTP request: its route, payload and answer.
Methods added later always come with a default implementation.
Required Associated Constants§
Sourceconst ROUTE: Route
const ROUTE: Route
The route: method, path template ({param} placeholders) and whether a Bearer token is
required. Always one entry of routes::ALL.
Sourceconst PAYLOAD: PayloadKind
const PAYLOAD: PayloadKind
How the payload travels.
Required Associated Types§
Sourcetype Payload: Serialize + DeserializeOwned
type Payload: Serialize + DeserializeOwned
What is sent: the JSON body, the query parameters, or NoPayload.
Sourcetype Response: Serialize + DeserializeOwned
type Response: Serialize + DeserializeOwned
The answer’s JSON on success (2xx).
Required Methods§
Sourcefn from_parts(
params: &PathParams,
payload: Self::Payload,
) -> Result<Self, ApiError>
fn from_parts( params: &PathParams, payload: Self::Payload, ) -> Result<Self, ApiError>
The call from what a server received: the path parameters by name and the decoded
payload. Checks the shape of the path parameters (400 bad_request for an id that is not
a number or an invalid name); the payload’s own rules are its validate(), which the
server runs.
Provided Methods§
Sourcefn path_params(&self) -> PathParams
fn path_params(&self) -> PathParams
The values of the path’s placeholders (none for a route without parameters).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".