use http::StatusCode;
use poem::{Route, Server, get, handler, listener::TcpListener};
use problem_details::{JsonProblemDetails, ProblemDetails, XmlProblemDetails};
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let app = Route::new()
.at("/", get(default))
.at("/json", get(json))
.at("/xml", get(xml));
Server::new(TcpListener::bind("127.0.0.1:3000"))
.run(app)
.await
}
#[handler]
async fn default() -> Result<&'static str, ProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT).with_detail("short and stout"))
}
#[handler]
async fn json() -> Result<&'static str, JsonProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT)
.with_detail("short and stout")
.into())
}
#[handler]
async fn xml() -> Result<&'static str, XmlProblemDetails> {
Err(ProblemDetails::from_status_code(StatusCode::IM_A_TEAPOT)
.with_detail("short and stout")
.into())
}