Introduce actix web template
Signed-off-by: jinhai <haijin.chn@gmail.com>
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -1,3 +1,19 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use actix_web::{get, web, App, HttpServer, Responder};
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> impl Responder {
|
||||
"Hello, World!"
|
||||
}
|
||||
|
||||
#[get("/{name}")]
|
||||
async fn hello(name: web::Path<String>) -> impl Responder {
|
||||
format!("Hello {}!", &name)
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(index).service(hello))
|
||||
.bind(("127.0.0.1", 9090))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user