#[route_param]Expand description
Extracts a specific route parameter into a variable.
This attribute macro retrieves a specific route parameter by key and makes it available as a variable. Route parameters are extracted from the URL path segments.
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/route_param/:test")]
struct RouteParam;
impl ServerHook for RouteParam {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("route param: {request_route_param:?}"))]
#[route_param("test" => request_route_param)]
async fn handle(self, ctx: &Context) {}
}
impl RouteParam {
#[route_param("test" => request_route_param)]
async fn route_param_with_ref_self(&self, ctx: &Context) {}
}
#[route_param("test" => request_route_param)]
async fn standalone_route_param_handler(ctx: &Context) {}The macro accepts a key-to-variable mapping in the format "key" => variable_name.
The variable will be available as an Option<String> in the function scope.