use actix_web::{App, HttpServer, web};
use http::StatusCode;
use problem_details::{JsonProblemDetails, ProblemDetails, XmlProblemDetails};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(default))
.route("/json", web::get().to(json))
.route("/xml", web::get().to(xml))
})
.bind(("0.0.0.0", 3000))?
.run()
.await
}
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())
}