1
0
mirror of https://github.com/actix/actix-website synced 2025-03-15 20:53:07 +01:00
2022-02-26 03:56:24 +00:00

24 lines
567 B
Rust

// <request-routing>
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
async fn index(_req: HttpRequest) -> impl Responder {
"Hello from the index page."
}
async fn hello(path: web::Path<String>) -> impl Responder {
format!("Hello {}!", &path)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(web::resource("/").to(index))
.service(web::resource("/{name}").to(hello))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
// </request-routing>