1
0
mirror of https://github.com/actix/actix-website synced 2024-12-02 19:52:23 +01:00
actix-website/examples/extractors/src/path_three.rs

27 lines
674 B
Rust
Raw Normal View History

2019-06-28 19:31:30 +02:00
use actix_web::{web, HttpRequest, Result};
// <path-three>
async fn index(req: HttpRequest) -> Result<String> {
2020-01-02 13:33:33 +01: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))
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-06-28 19:31:30 +02:00
use actix_web::{App, HttpServer};
HttpServer::new(|| {
App::new().route(
"/users/{userid}/{friend}", // <- define path parameters
web::get().to(index),
)
})
.bind("127.0.0.1:8088")?
.run()
.await
}
// </path-three>