Skip to main content

unknown_method

Attribute Macro unknown_method 

Source
#[unknown_method]
Expand description

Restricts function execution to unknown HTTP methods only.

This attribute macro ensures the decorated function only executes when the incoming request uses an HTTP method that is not one of the standard methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, TRACE). Requests with standard methods will be filtered out.

ยงUsage

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

#[route("/unknown_method")]
struct UnknownMethod;

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

    #[prologue_macros(
        clear_response_headers,
        filter(ctx.get_request().get_method().is_unknown()),
        response_body("unknown_method")
    )]
    async fn handle(self, ctx: &mut Context) {}
}

impl UnknownMethod {
    #[unknown_method]
    async fn unknown_method_with_ref_self(&self, ctx: &mut Context) {}
}

#[unknown_method]
async fn standalone_unknown_method_handler(ctx: &mut Context) {}

The macro takes no parameters and should be applied directly to async functions that accept a &mut Context parameter.