2019-06-13 00:14:10 +02:00
|
|
|
// <main-example>
|
2019-06-17 05:37:14 +02:00
|
|
|
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
2019-06-13 00:14:10 +02:00
|
|
|
|
2019-12-28 17:38:51 +01:00
|
|
|
async fn greet(req: HttpRequest) -> impl Responder {
|
2019-06-13 00:14:10 +02:00
|
|
|
let name = req.match_info().get("name").unwrap_or("World");
|
2019-06-17 05:37:14 +02:00
|
|
|
format!("Hello {}!", &name)
|
2019-06-13 00:14:10 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:21:54 +02:00
|
|
|
#[actix_web::main]
|
2019-12-28 17:38:51 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-13 00:14:10 +02:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
2019-06-19 20:24:31 +02:00
|
|
|
.route("/", web::get().to(greet))
|
|
|
|
.route("/{name}", web::get().to(greet))
|
2019-06-13 00:14:10 +02:00
|
|
|
})
|
2022-02-26 04:56:24 +01:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-13 00:14:10 +02:00
|
|
|
.run()
|
2019-12-28 17:38:51 +01:00
|
|
|
.await
|
2019-06-13 00:14:10 +02:00
|
|
|
}
|
|
|
|
// </main-example>
|