Middleware
Overview
Middleware is useful for adding other libs for additional features. Local middleware will be replaced with AOP soon.
Note, current middleware API is experimental. There can be breaking changes in next release.
For now, middleware is pretty trivial. You can use @Middleware decorator and define it on route or on whole controller.
Simple example:
Decorators
There are only 1 decorator for middleware purposes.
@Middleware(...functions: MiddlewareFunction[]
- set middleware for only one path, or set middleware for whole controller. Accepts unlimited number of middleware functions.
Don't forget about function context. You should set it manually or use lambda functions instead.
Purposes
Unfortunately, due to middleware structure, dependency injection cannot be applied for middleware functions. It should be used only for request data preprocessing, parsing and etc.
Check out future releases for AOP
AOP will solve most middleware cases
Last updated