request_query

Attribute Macro request_query 

Source
#[request_query]
Expand description

Extracts a specific request query parameter into a variable.

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.

ยง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_option),
        response_body(&format!("request query: {request_query_option:?}")),
        send
    )]
    async fn handle(self, ctx: &Context) {}
}

impl RequestQuery {
    #[request_query("test" => request_query_option)]
    async fn request_query_with_ref_self(&self, ctx: &Context) {}
}

#[request_query("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<String> in the function scope.

Supports multiple parameters: #[request_query("k1" => v1, "k2" => v2)]