2019-06-12 18:14:10 -04:00
|
|
|
// <request-routing>
|
2022-07-16 11:59:20 +02:00
|
|
|
use actix_web::{get, web, App, HttpRequest, HttpServer, Responder};
|
2019-06-12 18:14:10 -04:00
|
|
|
|
2022-07-16 11:59:20 +02:00
|
|
|
#[get("/")]
|
2019-12-29 02:09:52 +09:00
|
|
|
async fn index(_req: HttpRequest) -> impl Responder {
|
2019-06-16 23:37:14 -04:00
|
|
|
"Hello from the index page."
|
2019-06-12 18:14:10 -04:00
|
|
|
}
|
|
|
|
|
2019-12-29 02:09:52 +09:00
|
|
|
async fn hello(path: web::Path<String>) -> impl Responder {
|
2019-06-16 23:37:14 -04:00
|
|
|
format!("Hello {}!", &path)
|
2019-06-12 18:14:10 -04:00
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 02:09:52 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-12 18:14:10 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
2022-07-16 11:59:20 +02:00
|
|
|
.service(index)
|
|
|
|
.route("/{name}", web::get().to(hello))
|
2019-06-12 18:14:10 -04:00
|
|
|
})
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-12 18:14:10 -04:00
|
|
|
.run()
|
2019-12-29 02:09:52 +09:00
|
|
|
.await
|
2019-06-12 18:14:10 -04:00
|
|
|
}
|
|
|
|
// </request-routing>
|