#[request_query_option]Expand description
Extracts a specific request query parameter into a variable wrapped in Option type.
This attribute macro retrieves a specific request query parameter by key and makes it available as an Option variable. Query parameters are extracted from the URL request query string and wrapped in an Option type to safely handle cases where the parameter may not exist.
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_query_option")]
struct RequestQuery;
impl ServerHook for RequestQuery {
async fn new(_ctx: &Context) -> Self {
Self
}
#[prologue_macros(
request_query_option("test" => request_query_option),
response_body(&format!("request query: {request_query_option:?}")),
send
)]
async fn handle(self, ctx: &Context) {}
}
impl RequestQuery {
#[request_query_option("test" => request_query_option)]
async fn request_query_with_ref_self(&self, ctx: &Context) {}
}
#[request_query_option("test" => request_query_option)]
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 Option<RequestQuerysValue> in the function scope.
Supports multiple parameters: #[request_query_option("k1" => v1, "k2" => v2)]