2019-06-13 00:14:10 +02:00
|
|
|
// <main-example>
|
2019-06-17 05:37:14 +02:00
|
|
|
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
2019-06-13 00:14:10 +02:00
|
|
|
|
2019-06-17 05:37:14 +02:00
|
|
|
fn greet(req: HttpRequest) -> impl Responder {
|
2019-06-13 00:14:10 +02:00
|
|
|
let name = req.match_info().get("name").unwrap_or("World");
|
2019-06-17 05:37:14 +02:00
|
|
|
format!("Hello {}!", &name)
|
2019-06-13 00:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2019-06-13 00:14:10 +02:00
|
|
|
.run()
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
// </main-example>
|