add actix-web

This commit is contained in:
2020-04-18 02:26:07 +08:00
parent ef06866d10
commit 1267c4ed30
3 changed files with 1519 additions and 0 deletions

32
actix-web/src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
use actix_web::{get, web, App, HttpServer, Responder, HttpRequest, HttpResponse};
#[get("/{id}/{name}/index.html")]
async fn index(info: web::Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0)
}
#[get("/name")]
async fn index_name() -> impl Responder {
format!("Hello name!\n")
}
async fn index2(req: HttpRequest) -> HttpResponse {
println!("{:?}", req);
HttpResponse::Ok()
.content_type("text/plain")
.body("Welcome!\n")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
println!("Listen at: http://127.0.0.1:8080/");
HttpServer::new(|| App::new()
.service(index)
.service(index_name)
.service(web::resource("/").to(index2))
)
.bind("127.0.0.1:8080")?
.run()
.await
}