Trait hapic::JsonApiCall
source · pub trait JsonApiCall: Sized + Send {
type Output;
type JsonResponse: for<'a> Deserialize<'a>;
type JsonRequest: Serialize;
// Required methods
fn uri(&self, endpoint: &str) -> String;
fn try_into_request(self) -> Result<Self::JsonRequest, Error>;
fn parse_json_response(
status: StatusCode,
resp: Result<Self::JsonResponse>
) -> Result<Self::Output, Error>;
// Provided methods
fn method(&self) -> Method { ... }
fn modify_request(&self, request_builder: Builder) -> Builder { ... }
}Expand description
A JSON API call. (See also: SimpleApiCall)
This can be implemented manually, or by using the json_api_call macro.
Implementers of JsonApiCall, automatically implement ApiCall and therefore RawApiCall.
Required Associated Types§
sourcetype JsonResponse: for<'a> Deserialize<'a>
type JsonResponse: for<'a> Deserialize<'a>
The response type of the call, as is returned by the server.
This is passed through Self::parse_json_response to generate the Output value.
sourcetype JsonRequest: Serialize
type JsonRequest: Serialize
The request that is sent to the server. self is converted to this type, using
Self::try_into_request before making the API call.
Required Methods§
sourcefn try_into_request(self) -> Result<Self::JsonRequest, Error>
fn try_into_request(self) -> Result<Self::JsonRequest, Error>
Convert self to a Self::JsonRequest. This is called before making the HTTP POST
request.
sourcefn parse_json_response(
status: StatusCode,
resp: Result<Self::JsonResponse>
) -> Result<Self::Output, Error>
fn parse_json_response( status: StatusCode, resp: Result<Self::JsonResponse> ) -> Result<Self::Output, Error>
Convert a Self::JsonResponse, as received from the server, into Self::Output.
Provided Methods§
sourcefn modify_request(&self, request_builder: Builder) -> Builder
fn modify_request(&self, request_builder: Builder) -> Builder
A hook used to modify the request before it’s finalised. This is called directly before the
body method on the builder is called.