add actix-web
This commit is contained in:
1475
actix-web/Cargo.lock
generated
Normal file
1475
actix-web/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
actix-web/Cargo.toml
Normal file
12
actix-web/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "actix-web"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "2"
|
||||||
|
actix-rt = "1"
|
||||||
|
|
||||||
32
actix-web/src/main.rs
Normal file
32
actix-web/src/main.rs
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user