Last active
October 15, 2020 19:43
-
-
Save tiziano88/f98964029ac255de264de24ee098e746 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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