1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 16:52:59 +01:00
actix-website/examples/main-example/src/main.rs

21 lines
514 B
Rust
Raw Normal View History

// <main-example>
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
fn greet(req: HttpRequest) -> HttpResponse {
let name = req.match_info().get("name").unwrap_or("World");
HttpResponse::Ok().body(format!("Hello {}!", &name))
}
fn main() {
HttpServer::new(|| {
App::new()
.service(web::resource("/").to(greet))
.service(web::resource("/{name}").to(greet))
})
2019-06-13 06:32:48 +02:00
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
// </main-example>