pub trait RequestHandler<B> {
    type Successful;
    type Unsuccessful;
    type BuildError;

    fn build_request(
        &self,
        builder: RequestBuilder,
        request_body: &Option<B>,
        attempt_count: u8
    ) -> Result<Request, Self::BuildError>; fn handle_response(
        &self,
        status: StatusCode,
        headers: HeaderMap,
        response_body: Bytes
    ) -> Result<Self::Successful, Self::Unsuccessful>; fn request_config(&self) -> RequestConfig { ... } }
Expand description

A trait which is used to process requests and responses for the Client.

Required Associated Types§

The type which is returned to the caller of Client::request() when the response was successful.

The type which is returned to the caller of Client::request() when the response was unsuccessful.

The type that represents an error occurred in build_request().

Required Methods§

Build a HTTP request to be sent.

Implementors have to decide how to include the request_body into the builder. Implementors can also perform other operations (such as authorization) on the request.

Handle a HTTP response before it is returned to the caller of Client::request().

You can verify, parse, etc… the response here before it is returned to the caller.

Examples
fn handle_response(&self, status: StatusCode, _: HeaderMap, response_body: Bytes) -> Result<String, ()> {
    if status.is_success() {
        let body = std::str::from_utf8(&response_body).expect("body should be valid UTF-8").to_owned();
        Ok(body)
    } else {
        Err(())
    }
}

Provided Methods§

Returns a RequestConfig that will be used to send a HTTP reqeust.

Implementors§