mirror of
https://github.com/actix/actix-website
synced 2024-11-28 02:22:57 +01:00
21 lines
514 B
Rust
21 lines
514 B
Rust
// <main-example>
|
|
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
|
|
|
async fn greet(req: HttpRequest) -> impl Responder {
|
|
let name = req.match_info().get("name").unwrap_or("World");
|
|
format!("Hello {}!", &name)
|
|
}
|
|
|
|
#[actix_rt::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| {
|
|
App::new()
|
|
.route("/", web::get().to(greet))
|
|
.route("/{name}", web::get().to(greet))
|
|
})
|
|
.bind("127.0.0.1:8088")?
|
|
.run()
|
|
.await
|
|
}
|
|
// </main-example>
|