1
0
mirror of https://github.com/actix/actix-website synced 2024-12-04 12:41:55 +01:00
actix-website/examples/flexible-responders/src/main.rs
Santiago 8393aea71a
migrate to docusaurus (v2) (#266)
Co-authored-by: ibraheemdev <ibrah1440@gmail.com>
2022-07-16 18:59:20 +09:00

30 lines
652 B
Rust

use actix_web::{web, App, HttpServer, Responder};
use serde::Serialize;
// <flexible-responders>
#[derive(Serialize)]
struct Measurement {
temperature: f32,
}
async fn hello_world() -> impl Responder {
"Hello World!"
}
async fn current_temperature() -> impl Responder {
web::Json(Measurement { temperature: 42.3 })
}
// </flexible-responders>
#[actix_web::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", 8080))?
.run()
.await
}