2020-09-12 17:21:54 +02:00
|
|
|
use actix_web::{get, HttpRequest, Result};
|
2019-06-20 10:26:34 +02:00
|
|
|
|
|
|
|
// <path-three>
|
2022-04-07 16:54:55 +02:00
|
|
|
#[get("/users/{user_id}/{friend}")] // <- define path parameters
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index(req: HttpRequest) -> Result<String> {
|
2020-09-12 17:21:54 +02:00
|
|
|
let name: String = req.match_info().get("friend").unwrap().parse().unwrap();
|
2022-04-07 16:54:55 +02:00
|
|
|
let userid: i32 = req.match_info().query("user_id").parse().unwrap();
|
2019-06-20 10:26:34 +02:00
|
|
|
|
2022-04-07 16:54:55 +02:00
|
|
|
Ok(format!("Welcome {}, user_id {}!", name, userid))
|
2019-06-20 10:26:34 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:21:54 +02:00
|
|
|
#[actix_web::main]
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-28 19:31:30 +02:00
|
|
|
use actix_web::{App, HttpServer};
|
|
|
|
|
2020-09-12 17:21:54 +02:00
|
|
|
HttpServer::new(|| App::new().service(index))
|
2022-02-26 04:56:24 +01:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2020-09-12 17:21:54 +02:00
|
|
|
.run()
|
|
|
|
.await
|
2019-06-20 10:26:34 +02:00
|
|
|
}
|
|
|
|
// </path-three>
|