mirror of
https://github.com/actix/actix-website
synced 2025-03-14 20:26:26 +01:00
26 lines
633 B
Rust
26 lines
633 B
Rust
use actix_web::{web, App, HttpResponse, HttpServer};
|
|
|
|
// <scope>
|
|
async fn show_users() -> HttpResponse {
|
|
HttpResponse::Ok().body("Show users")
|
|
}
|
|
|
|
async fn user_detail(path: web::Path<(u32,)>) -> HttpResponse {
|
|
HttpResponse::Ok().body(format!("User detail: {}", path.0))
|
|
}
|
|
|
|
#[actix_rt::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| {
|
|
App::new().service(
|
|
web::scope("/users")
|
|
.route("/show", web::get().to(show_users))
|
|
.route("/show/{id}", web::get().to(user_detail)),
|
|
)
|
|
})
|
|
.bind("127.0.0.1:8088")?
|
|
.run()
|
|
.await
|
|
}
|
|
// </scope>
|