#[request_query]Expand description
Extracts a specific request query parameter into a variable with panic on missing value.
This attribute macro retrieves a specific request query parameter by key and makes it available as a variable. Query parameters are extracted from the URL request query string. If the requested query parameter does not exist, the function will panic with an error message.
§Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_query")]
struct RequestQuery;
impl ServerHook for RequestQuery {
async fn new(_ctx: &Context) -> Self {
Self
}
#[prologue_macros(
request_query("test" => request_query),
response_body(&format!("request query: {request_query}")),
send
)]
async fn handle(self, ctx: &Context) {}
}
impl RequestQuery {
#[request_query("test" => request_query)]
async fn request_query_with_ref_self(&self, ctx: &Context) {}
}
#[request_query("test" => request_query)]
async fn standalone_request_query_handler(ctx: &Context) {}The macro accepts a key-to-variable mapping in the format "key" => variable_name.
The variable will be available as an RequestQuerysValue in the function scope.
Supports multiple parameters: #[request_query("k1" => v1, "k2" => v2)]
§Panics
This macro will panic if the requested query parameter does not exist in the URL query string.