request_cookie

Attribute Macro request_cookie 

Source
#[request_cookie]
Expand description

Extracts a specific cookie value or all cookies into a variable.

This attribute macro supports two syntaxes:

  1. cookie(key => variable_name) - Extract a specific cookie value by key
  2. cookie(variable_name) - Extract all cookies as a raw string

ยงUsage

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

#[route("/cookie")]
struct Cookie;

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

    #[response_body(&format!("Session cookie: {session_cookie_opt:?}"))]
    #[request_cookie("test" => session_cookie_opt)]
    async fn handle(self, ctx: &Context) {}
}

For specific cookie extraction, the variable will be available as Option<String>. For all cookies extraction, the variable will be available as String.