request_cookies

Attribute Macro request_cookies 

Source
#[request_cookies]
Expand description

Extracts all cookies as a raw string into a variable.

This attribute macro retrieves the entire Cookie header from the request and makes it available as a String variable. If no Cookie header is present, an empty string is used.

ยงUsage

use hyperlane::*;
use hyperlane_macros::*;

#[route("/cookies")]
struct Cookies;

impl ServerHook for Cookies {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[response_body(&format!("All cookies: {cookie_value:?}"))]
    #[request_cookies(cookie_value)]
    async fn handle(self, ctx: &Context) {}
}

The macro accepts a variable name that will contain the Cookie header value. The variable will be available as a String in the function scope.