1
0
mirror of https://github.com/actix/actix-website synced 2025-02-09 06:45:37 +01:00

28 lines
640 B
Rust
Raw Normal View History

2020-09-12 16:21:54 +01:00
use actix_web::{get, web, App, HttpResponse, HttpServer};
2018-05-24 10:13:55 -07:00
2019-06-13 03:24:25 -04:00
// <scope>
2020-09-12 16:21:54 +01:00
#[get("/show")]
2019-12-29 04:10:02 +09:00
async fn show_users() -> HttpResponse {
2019-06-25 18:20:36 -04:00
HttpResponse::Ok().body("Show users")
}
2020-09-12 16:21:54 +01:00
#[get("/show/{id}")]
2019-12-29 04:10:02 +09:00
async fn user_detail(path: web::Path<(u32,)>) -> HttpResponse {
2020-09-12 16:21:54 +01:00
HttpResponse::Ok().body(format!("User detail: {}", path.into_inner().0))
2018-05-24 10:13:55 -07:00
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 04:10:02 +09:00
async fn main() -> std::io::Result<()> {
2019-06-25 18:20:36 -04:00
HttpServer::new(|| {
App::new().service(
web::scope("/users")
2020-09-12 16:21:54 +01:00
.service(show_users)
.service(user_detail),
2019-06-25 18:20:36 -04:00
)
})
2020-09-12 16:21:54 +01:00
.bind("127.0.0.1:8080")?
2019-06-25 18:20:36 -04:00
.run()
2019-12-29 04:10:02 +09:00
.await
2018-05-24 10:13:55 -07:00
}
2019-06-13 03:24:25 -04:00
// </scope>