Skip to content

Commit

Permalink
Add example for using actix
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeconnolly committed Aug 2, 2019
1 parent 2907641 commit 5d78cb2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
use actix_web::{web, App, HttpRequest, HttpServer, Responder};

fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}

fn main() {
println!("Hello, world!");
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8000")
.expect("Can not bind to port 8000")
.run()
.unwrap();
}

0 comments on commit 5d78cb2

Please sign in to comment.