Skip to main content

Middlewares

Middleware is a common pattern used in software development to handle requests and responses in a modular and reusable way. In the context of AxiSpark.js, middleware is a type of engine step that allows you to intercept and modify the execution flow of a request before it reaches the main transport step.

Middleware example​

middleware.ts
@Middleware({ transport: ExecutionTransport.Http, global: true })
export class MyMiddleware {
@Handle()
public async use(@Context() context: HttpContext) {
...
}
}

A Middleware class can have multple methods decorated with @Handle(), each method will be executed in the order they are defined in the class. These could be useful in some cases, but it is recommended to have only one method per Middleware class to avoid confusion and to keep the code clean and maintainable.