Trait HttpResponse

Source
pub trait HttpResponse {
    // Required methods
    fn to_result(self) -> Result<Response<Body>, HttpError>;
    fn response_metadata() -> ApiEndpointResponse;
    fn status_code(&self) -> StatusCode;
}
Expand description

HttpResponse must produce a Result<Response<Body>, HttpError> and generate the response metadata. Typically one should use Response<Body> or an implementation of HttpTypedResponse.

Required Methods§

Source

fn to_result(self) -> Result<Response<Body>, HttpError>

Generate the response to the HTTP call.

Source

fn response_metadata() -> ApiEndpointResponse

Extract status code and structure metadata for the non-error response. Type information for errors is handled generically across all endpoints.

Source

fn status_code(&self) -> StatusCode

Extract the status code from the concrete response instance.

This may differ from the value extracted from response_metadata() in error cases or if one has built a response manually using something like Response<Body>.

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.

Implementations on Foreign Types§

Source§

impl HttpResponse for Response<Body>

Response<Body> is used for free-form responses. The implementation of to_result() is trivial, and we don’t have any typed metadata to return.

Implementors§

Source§

impl<T> HttpResponse for T

Provide results and metadata generation for all implementing types.

Source§

impl<T: HttpCodedResponse, H: JsonSchema + Serialize + Send + Sync + 'static> HttpResponse for HttpResponseHeaders<T, H>