1
0
mirror of https://github.com/actix/actix-website synced 2025-03-20 06:35:18 +01:00

31 lines
643 B
Rust
Raw Normal View History

2019-06-16 23:17:17 -04:00
// <multi>
2020-09-12 16:21:54 +01:00
use actix_web::{get, web};
2019-06-16 23:17:17 -04:00
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
2020-09-12 16:21:54 +01:00
#[get("/users/{user_id}/{friend}")] // <- define path parameters
2020-01-02 18:33:33 +06:00
async fn index(
2020-09-12 16:21:54 +01:00
web::Path((user_id, friend)): web::Path<(u32, String)>,
query: web::Query<Info>,
2020-01-02 18:33:33 +06:00
) -> String {
2019-06-20 04:20:12 -04:00
format!(
2020-09-12 16:21:54 +01:00
"Welcome {}, friend {}, user_id {}!",
query.username, friend, user_id
2019-06-20 04:20:12 -04:00
)
2019-06-16 23:17:17 -04:00
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
2019-06-28 13:31:30 -04:00
use actix_web::{App, HttpServer};
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.run()
.await
2019-06-16 23:17:17 -04:00
}
// </multi>