Skip to main content

module

Attribute Macro module 

Source
#[module]
Expand description

Groups handlers under a shared URL prefix and optional middleware.

§Syntax

#[module(prefix = "/api/v1")]
#[module(prefix = "/api/v1", middleware = [auth_required, require_role("admin")])]
mod my_module { ... }

All #[handler] attributes inside the module are automatically rewritten to include the module association so they are grouped correctly at startup. The module is registered via inventory and collected by AppBuilder.

Bare mod foo; declarations inside the module body are allowed. Inline nested mod foo { ... } blocks are not supported and will produce a compile error, because their handlers would not receive the outer module’s prefix.