mirror of
https://github.com/actix/actix-website
synced 2025-01-22 16:15:56 +01:00
Update flexible-responders
This commit is contained in:
parent
de7c7d3aed
commit
37bd5e5da2
@ -4,5 +4,6 @@ version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
actix-web = "2.0"
|
||||
actix-rt = "1.0"
|
||||
serde = "1.0"
|
||||
|
@ -7,23 +7,23 @@ struct Measurement {
|
||||
temperature: f32,
|
||||
}
|
||||
|
||||
fn hello_world() -> impl Responder {
|
||||
async fn hello_world() -> impl Responder {
|
||||
"Hello World!"
|
||||
}
|
||||
|
||||
fn current_temperature() -> impl Responder {
|
||||
async fn current_temperature() -> impl Responder {
|
||||
web::Json(Measurement { temperature: 42.3 })
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/").to(hello_world))
|
||||
.service(web::resource("/temp").to(current_temperature))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </flexible-responders>
|
||||
|
Loading…
x
Reference in New Issue
Block a user