2019-06-28 19:31:30 +02:00
|
|
|
use actix_web::{web, HttpRequest, Result};
|
2019-06-20 10:26:34 +02:00
|
|
|
|
|
|
|
// <path-three>
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index(req: HttpRequest) -> Result<String> {
|
2019-06-20 10:26:34 +02:00
|
|
|
let name: String = req.match_info().get("friend").unwrap().parse().unwrap();
|
|
|
|
let userid: i32 = req.match_info().query("userid").parse().unwrap();
|
|
|
|
|
|
|
|
Ok(format!("Welcome {}, userid {}!", name, userid))
|
|
|
|
}
|
|
|
|
|
2019-12-28 16:26:17 +01:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-28 19:31:30 +02:00
|
|
|
use actix_web::{App, HttpServer};
|
|
|
|
|
2019-06-20 10:26:34 +02: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 10:26:34 +02:00
|
|
|
.run()
|
2019-12-28 16:26:17 +01:00
|
|
|
.await
|
2019-06-20 10:26:34 +02:00
|
|
|
}
|
|
|
|
// </path-three>
|