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§

source

type Output

The output type of the call.

source

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.

source

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§

source

fn uri(&self, endpoint: &str) -> String

Generate the URI to make the HTTP POST request to.

source

fn try_into_request(self) -> Result<Self::JsonRequest, Error>

Convert self to a Self::JsonRequest. This is called before making the HTTP POST request.

source

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§

source

fn method(&self) -> Method

The HTTP request method.

source

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.

Object Safety§

This trait is not object safe.

Implementors§