1
0
mirror of https://github.com/actix/actix-website synced 2024-11-28 02:22:57 +01:00
actix-website/examples/main-example/src/main.rs

21 lines
515 B
Rust
Raw Normal View History

// <main-example>
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
2019-12-28 17:38:51 +01:00
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
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<()> {
HttpServer::new(|| {
App::new()
2019-06-19 20:24:31 +02:00
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
2020-09-12 17:21:54 +02:00
.bind("127.0.0.1:8080")?
.run()
2019-12-28 17:38:51 +01:00
.await
}
// </main-example>