Skip to main content

Interceptors

Interceptors are a type of engine step that allow you to intercept and modify the execution flow of a request before it reaches the main transport step. In the context of AxiSpark.js, interceptors are used to perform additional operations before or after the main transport step is executed.

Interceptor example​

interceptor.ts
@Interceptor({ transport: ExecutionTransport.Http, global: false })
export class MyInterceptor {
@Before()
public async before(@Context() context: HttpContext) {
...
}

@After()
public async after(@Context() context: HttpContext) {
...
}
}

A Interceptor class can have multiple methods decorated with @Before() or @After(), 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 Interceptor class to avoid confusion and to keep the code clean and maintainable.

You don't need to use both @Before() and @After() decorators in the same Interceptor class. You can choose to use either one or both, depending on your needs.