path_variable!() { /* proc-macro */ }Expand description
The path_variable macro extracts a path parameter from the URL.
This macro should be applied to function parameters to deserialize path variables.
The extracted value can be converted into any Rust primitive type or any type
that implements the FromAsyncStr trait.
§Example
ⓘ
#[get(url = "/user/{name}")]
fn get_user(#[path_variable] name: String) -> String {
name
}A request like GET /user/john will return "john".
You can also deserialize the path variable into a more complex type that
implements FromAsyncStr:
ⓘ
#[get(url = "/user/{id}")]
async fn get_user(#[path_variable] user: User) -> User {
user
}If User implements FromAsyncStr, the framework will automatically fetch
the user from a database or other source based on the id provided in the URL.