mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Fixes missed example and config for extractors.
This commit is contained in:
23
examples/extractors/src/path_three.rs
Normal file
23
examples/extractors/src/path_three.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Result};
|
||||
|
||||
// <path-three>
|
||||
fn index(req: HttpRequest) -> Result<String> {
|
||||
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))
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new().route(
|
||||
"/users/{userid}/{friend}", // <- define path parameters
|
||||
web::get().to(index),
|
||||
)
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </path-three>
|
Reference in New Issue
Block a user