Attribute Macro pavex::request::path::PathParams
#[PathParams]
Expand description
Derive (de)serialization logic for a type that is going to be used to extract path parameters.
This macro derives StructuralDeserialize
, serde::Serialize
and serde::Deserialize
for the type that it is applied to.
Check out PathParams
for more details on how to work with
path parameters in Pavex.
Check out StructuralDeserialize
if you are curious about the rationale behind this
macro.
ยงExample
use pavex::f;
use pavex::blueprint::{router::GET, Blueprint, constructor::Lifecycle};
use pavex::request::path::PathParams;
fn blueprint() -> Blueprint { ///
let mut bp = Blueprint::new();
// [...]
// Register a route with a path parameter, `:home_id`.
bp.route(GET, "/home/:home_id", f!(crate::get_home));
}
#[PathParams]
struct Home {
home_id: u32
}
fn get_home(params: &PathParams<Home>) -> String {
format!("The identifier for this home is: {}", params.0.home_id)
}