Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Macro

Middleware(using:body:)

Groups routes using a controller’s middleware property or factory.
@freestanding(declaration) macro Middleware<Controller>(using middleware: (Controller) -> any Middleware, body: () -> Void)

Overview

For example, #Middleware(using: \Self.loggingMiddleware) { ... }, or #Middleware(using: { (controller: Self) in APIMiddleware(client: controller.client) }) { ... }. The key path or factory is type-checked at the declaration site and evaluated with self in the generated boot(routes:), once per route. Store the middleware on the controller if the routes should share the same middleware instance.