2019-06-16 23:17:17 -04:00
|
|
|
// <path-two>
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, web, Result};
|
2019-06-16 23:17:17 -04:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct Info {
|
2020-09-12 16:21:54 +01:00
|
|
|
user_id: u32,
|
2019-06-16 23:17:17 -04:00
|
|
|
friend: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// extract path info using serde
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/users/{user_id}/{friend}")] // <- define path parameters
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index(info: web::Path<Info>) -> Result<String> {
|
2020-09-12 16:21:54 +01:00
|
|
|
Ok(format!(
|
|
|
|
"Welcome {}, user_id {}!",
|
|
|
|
info.friend, info.user_id
|
|
|
|
))
|
2019-06-16 23:17:17 -04:00
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-28 16:26:17 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
// </path-two>
|