Skip to content

Instantly share code, notes, and snippets.

@tiziano88
Last active October 15, 2020 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiziano88/f98964029ac255de264de24ee098e746 to your computer and use it in GitHub Desktop.
Save tiziano88/f98964029ac255de264de24ee098e746 to your computer and use it in GitHub Desktop.
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Hello World server started");
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("[::]:8080")?
.run()
.await
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment