zino_http::response

Trait ResponseCode

Source
pub trait ResponseCode {
    type ErrorCode: Serialize;
    type BusinessCode: Serialize;

    const OK: Self;
    const BAD_REQUEST: Self;
    const INTERNAL_SERVER_ERROR: Self;

    // Required methods
    fn status_code(&self) -> u16;
    fn is_success(&self) -> bool;

    // Provided methods
    fn error_code(&self) -> Option<Self::ErrorCode> { ... }
    fn business_code(&self) -> Option<Self::BusinessCode> { ... }
    fn type_uri(&self) -> Option<SharedString> { ... }
    fn title(&self) -> Option<SharedString> { ... }
    fn message(&self) -> Option<SharedString> { ... }
}
Expand description

Trait for response code. See Problem Details for HTTP APIs.

Required Associated Constants§

Source

const OK: Self

200 Ok.

Source

const BAD_REQUEST: Self

400 Bad Request.

Source

const INTERNAL_SERVER_ERROR: Self

500 Internal Server Error.

Required Associated Types§

Source

type ErrorCode: Serialize

A type for the error code.

Source

type BusinessCode: Serialize

A type for the business code.

Required Methods§

Source

fn status_code(&self) -> u16

Status code.

Source

fn is_success(&self) -> bool

Returns true if the response is successful.

Provided Methods§

Source

fn error_code(&self) -> Option<Self::ErrorCode>

Error code.

Source

fn business_code(&self) -> Option<Self::BusinessCode>

Business code.

Source

fn type_uri(&self) -> Option<SharedString>

A URI reference that identifies the problem type. For successful response, it should be None.

Source

fn title(&self) -> Option<SharedString>

A short, human-readable summary of the problem type. For successful response, it should be None.

Source

fn message(&self) -> Option<SharedString>

A context-specific descriptive message. If the response is not successful, it should be a human-readable explanation specific to this occurrence of the problem.

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 ResponseCode for StatusCode

Source§

const OK: Self = Self::OK

Source§

const BAD_REQUEST: Self = Self::BAD_REQUEST

Source§

const INTERNAL_SERVER_ERROR: Self = Self::INTERNAL_SERVER_ERROR

Source§

type ErrorCode = Cow<'static, str>

Source§

type BusinessCode = u16

Source§

fn status_code(&self) -> u16

Source§

fn is_success(&self) -> bool

Source§

fn type_uri(&self) -> Option<SharedString>

Source§

fn title(&self) -> Option<SharedString>

Source§

fn message(&self) -> Option<SharedString>

Implementors§