poem_openapi

Trait ApiResponse

Source
pub trait ApiResponse: Sized {
    const BAD_REQUEST_HANDLER: bool = false;

    // Required methods
    fn meta() -> MetaResponses;
    fn register(registry: &mut Registry);

    // Provided method
    fn from_parse_request_error(err: Error) -> Self { ... }
}
Expand description

Represents an OpenAPI responses object.

§Provided Implementations

  • Binary<T: Type>

    A binary response with content type application/octet-stream.

  • Json<T: Type>

    A JSON response with content type application/json.

  • PlainText<T: Type>

    A utf8 string response with content type text/plain.

  • Attachment<T: Type>

    A file download response, the content type is application/octet-stream.

  • Response<T: Type>

    A response type use it to modify the status code and HTTP headers.

  • ()

    It means that this API does not have any response body.

  • poem::Result<T: ApiResponse>

    It means that an error may occur in this API.

  • Any type derived from the ApiResponse macro

    A complex response derived from the ApiResponse macro.

Provided Associated Constants§

Source

const BAD_REQUEST_HANDLER: bool = false

If true, it means that the response object has a custom bad request handler.

Required Methods§

Source

fn meta() -> MetaResponses

Gets metadata of this response.

Source

fn register(registry: &mut Registry)

Register the schema contained in this response object to the registry.

Provided Methods§

Source

fn from_parse_request_error(err: Error) -> Self

Convert poem::Error to this response object.

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 ApiResponse for StaticFileResponse

Source§

fn meta() -> MetaResponses

Source§

fn register(_registry: &mut Registry)

Source§

impl ApiResponse for ()

Source§

fn meta() -> MetaResponses

Source§

fn register(_registry: &mut Registry)

Source§

impl ApiResponse for Error

Source§

fn meta() -> MetaResponses

Source§

fn register(_registry: &mut Registry)

Source§

impl<F, Fut> ApiResponse for WebSocketUpgraded<F>
where F: FnOnce(WebSocketStream) -> Fut + Send + Sync + 'static, Fut: Future + Send + 'static,

Source§

fn meta() -> MetaResponses

Source§

fn register(_registry: &mut Registry)

Source§

impl<T, E> ApiResponse for Result<T, E>
where T: ApiResponse, E: ApiResponse + Into<Error> + Send + Sync + 'static,

Source§

const BAD_REQUEST_HANDLER: bool = T::BAD_REQUEST_HANDLER

Source§

fn meta() -> MetaResponses

Source§

fn register(registry: &mut Registry)

Source§

fn from_parse_request_error(err: Error) -> Self

Implementors§

Source§

impl<T: AsRef<[u8]> + Send> ApiResponse for Base64<T>

Source§

impl<T: Into<String> + Send> ApiResponse for Html<T>

Source§

impl<T: Into<String> + Send> ApiResponse for PlainText<T>

Source§

impl<T: Into<Body> + Send> ApiResponse for Attachment<T>

Source§

impl<T: Into<Body> + Send> ApiResponse for Binary<T>

Source§

impl<T: Stream<Item = E> + Send + 'static, E: Type + ToJSON> ApiResponse for EventStream<T>

Source§

impl<T: ApiResponse> ApiResponse for Response<T>

Source§

const BAD_REQUEST_HANDLER: bool = T::BAD_REQUEST_HANDLER

Source§

impl<T: ToJSON> ApiResponse for Json<T>

Source§

impl<T: ToXML> ApiResponse for Xml<T>

Source§

impl<T: ToYAML> ApiResponse for Yaml<T>