request_middleware

Attribute Macro request_middleware 

Source
#[request_middleware]
Expand description

Registers a function as a request middleware.

This attribute macro registers the decorated function to be executed as a middleware for incoming requests. This macro requires the #[hyperlane(server: Server)] macro to be used to define the server instance.

§Note

If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.

§Usage

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

#[request_middleware]
struct RequestMiddleware;

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

    #[epilogue_macros(
        response_status_code(200),
        response_version(HttpVersion::HTTP1_1),
        response_header(SERVER => HYPERLANE)
    )]
    async fn handle(self, ctx: &Context) {}
}

§Dependencies

This macro depends on the #[hyperlane(server: Server)] macro to define the server instance.