mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Cargo can't do nested workspaces.
This commit is contained in:
8
examples/flexible-responders/Cargo.toml
Normal file
8
examples/flexible-responders/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "flexible-responders"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
serde = "1.0"
|
29
examples/flexible-responders/src/main.rs
Normal file
29
examples/flexible-responders/src/main.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
use serde::Serialize;
|
||||
|
||||
// <flexible-responders>
|
||||
#[derive(Serialize)]
|
||||
struct Measurement {
|
||||
temperature: f32,
|
||||
}
|
||||
|
||||
fn hello_world() -> impl Responder {
|
||||
"Hello World!"
|
||||
}
|
||||
|
||||
fn current_temperature(_req: HttpRequest) -> impl Responder {
|
||||
web::Json(Measurement { temperature: 42.3 })
|
||||
}
|
||||
|
||||
fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/").to(hello_world))
|
||||
.service(web::resource("/temp").to(current_temperature))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </flexible-responders>
|
Reference in New Issue
Block a user