problem_details

Module axum

Source
Expand description

Axum response types for ProblemDetails.

Requires feature axum.

With the axum feature enabled, ProblemDetails implements IntoResponse using JsonProblemDetails. You can also return JsonProblemDetails to be specific. If you want to return XML, you can use XmlProblemDetails.

ยงExample

use axum::{routing::get, Router};
use http::StatusCode;
use problem_details::ProblemDetails;

async fn handler() -> Result<&'static str, ProblemDetails> {
    // always return a problem description
    Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT)
        .with_detail("short and stout"))
}

fn main() {
    let app = Router::new().route("/", get(handler));
    // build and run server...
}