1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00
This commit is contained in:
Rob Ede
2022-02-18 02:44:02 +00:00
parent aca1dab890
commit fbd3b228e9
48 changed files with 103 additions and 261 deletions

View File

@ -23,8 +23,7 @@ impl ResponseError for Error {
// builds the actual response to send back when an error occurs
fn error_response(&self) -> web::HttpResponse {
let err_json = json!({ "error": self.msg });
web::HttpResponse::build(StatusCode::from_u16(self.status).unwrap())
.json(err_json)
web::HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
}
}
@ -40,11 +39,9 @@ async fn main() -> io::Result<()> {
let ip_address = "127.0.0.1:8000";
println!("Running server on {}", ip_address);
HttpServer::new(|| {
App::new().service(web::resource("/").route(web::get().to(index)))
})
.bind(ip_address)
.expect("Can not bind to port 8000")
.run()
.await
HttpServer::new(|| App::new().service(web::resource("/").route(web::get().to(index))))
.bind(ip_address)
.expect("Can not bind to port 8000")
.run()
.await
}