1
0
mirror of https://github.com/actix/actix-website synced 2025-02-23 20:53:01 +01:00

25 lines
556 B
Rust
Raw Normal View History

// <request-routing>
use actix_web::{get, web, App, HttpRequest, HttpServer, Responder};
#[get("/")]
2019-12-29 02:09:52 +09:00
async fn index(_req: HttpRequest) -> impl Responder {
"Hello from the index page."
}
2019-12-29 02:09:52 +09:00
async fn hello(path: web::Path<String>) -> impl Responder {
format!("Hello {}!", &path)
}
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<()> {
HttpServer::new(|| {
App::new()
.service(index)
.route("/{name}", web::get().to(hello))
})
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
.run()
2019-12-29 02:09:52 +09:00
.await
}
// </request-routing>