2019-06-16 23:17:17 -04:00
|
|
|
// <path-two>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, Result};
|
2019-06-16 23:17:17 -04:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct Info {
|
|
|
|
userid: u32,
|
|
|
|
friend: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// extract path info using serde
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index(info: web::Path<Info>) -> Result<String> {
|
2019-06-19 00:20:50 -04:00
|
|
|
Ok(format!("Welcome {}, userid {}!", info.friend, info.userid))
|
2019-06-16 23:17:17 -04:00
|
|
|
}
|
|
|
|
|
2019-12-28 16:26:17 +01:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{App, HttpServer};
|
|
|
|
|
2019-06-20 04:20:12 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new().route(
|
|
|
|
"/users/{userid}/{friend}", // <- define path parameters
|
|
|
|
web::get().to(index),
|
|
|
|
)
|
|
|
|
})
|
2019-12-28 16:26:17 +01:00
|
|
|
.bind("127.0.0.1:8088")?
|
2019-06-20 04:20:12 -04:00
|
|
|
.run()
|
2019-12-28 16:26:17 +01:00
|
|
|
.await
|
2019-06-16 23:17:17 -04:00
|
|
|
}
|
|
|
|
// </path-two>
|