mirror of
https://github.com/actix/actix-website
synced 2024-11-24 16:52:59 +01:00
21 lines
541 B
Rust
21 lines
541 B
Rust
|
// <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))
|
||
|
})
|
||
|
.bind("127.0.0.1:8000")
|
||
|
.expect("Can not bind to port 8000")
|
||
|
.run()
|
||
|
.unwrap();
|
||
|
}
|
||
|
// </main-example>
|