use axum::{Router, routing::get};
use http::StatusCode;
use problem_details::{JsonProblemDetails, ProblemDetails, XmlProblemDetails};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(default))
.route("/json", get(json))
.route("/xml", get(xml));
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn default() -> Result<&'static str, ProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT).with_detail("short and stout"))
}
async fn json() -> Result<&'static str, JsonProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT)
.with_detail("short and stout")
.into())
}
async fn xml() -> Result<&'static str, XmlProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT)
.with_detail("short and stout")
.into())
}