1
0
mirror of https://github.com/actix/actix-website synced 2024-12-03 20:22:13 +01:00
actix-website/examples/flexible-responders/src/main.rs

30 lines
649 B
Rust
Raw Normal View History

2019-06-28 20:22:51 +02:00
use actix_web::{web, App, HttpServer, Responder};
use serde::Serialize;
// <flexible-responders>
#[derive(Serialize)]
struct Measurement {
temperature: f32,
}
2019-12-28 17:32:43 +01:00
async fn hello_world() -> impl Responder {
"Hello World!"
}
2019-12-28 17:32:43 +01:00
async fn current_temperature() -> impl Responder {
web::Json(Measurement { temperature: 42.3 })
}
2020-09-12 17:21:54 +02:00
#[actix_web::main]
2019-12-28 17:32:43 +01:00
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(web::resource("/").to(hello_world))
.service(web::resource("/temp").to(current_temperature))
})
2020-09-12 17:21:54 +02:00
.bind("127.0.0.1:8080")?
.run()
2019-12-28 17:32:43 +01:00
.await
}
// </flexible-responders>