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

26 lines
633 B
Rust
Raw Normal View History

2019-06-25 18:20:36 -04:00
use actix_web::{web, App, HttpResponse, HttpServer};
2018-05-24 10:13:55 -07:00
2019-06-13 03:24:25 -04:00
// <scope>
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")
}
2019-12-29 04:10:02 +09:00
async fn user_detail(path: web::Path<(u32,)>) -> HttpResponse {
2019-06-28 13:31:30 -04:00
HttpResponse::Ok().body(format!("User detail: {}", path.0))
2018-05-24 10:13:55 -07:00
}
2019-12-29 04:10:02 +09:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-06-25 18:20:36 -04:00
HttpServer::new(|| {
App::new().service(
web::scope("/users")
.route("/show", web::get().to(show_users))
.route("/show/{id}", web::get().to(user_detail)),
)
})
2019-12-29 04:10:02 +09:00
.bind("127.0.0.1:8088")?
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>