Guards
Guards are a type of engine step that allow you to validate the input data before it reaches the main transport step. In the context of AxiSpark.js, guards are used to ensure that the input data meets certain criteria before it is processed.
Guard example
guard.ts
@Guard({ transport: ExecutionTransport.Http, global: true })
export class MyGuard {
@Check()
public async use(@Context() context: HttpContext) {
...
}
}
A Guard class can have multiple methods decorated with
@Check(), 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 Guard class to avoid confusion and to keep the code clean and maintainable.