Skip to Content
HeronJS v4 is now available.
Versionv4HTTPInterceptor

HTTP Interceptors

4.7.0 uses framework request/reply functions and typed lifecycle hooks. Express next() middleware is no longer supported.

import 'reflect-metadata'; import {Rest, Get, Interceptors} from '@heronjs/express'; import type {HttpInterceptor} from '@heronjs/common'; const requestId: HttpInterceptor = ({request, response: reply}) => { reply.header({name: 'x-request-id', value: request.id}); }; @Rest('/health') @Interceptors([requestId]) export class HealthController { @Get({uri: '/'}) health() { return {ok: true}; } }

@Interceptors applies at class or method level. Register the controller in @Module({controllers: [...]}). Interceptors support values, Promises and Observables; finite interceptor execution is awaited.

For global behavior, pass options.interceptors to app.listen(). options.globalError accepts a HttpErrorInterceptor with {error, request, response}. Return a sanitized response rather than exposing internal exception details.

Use options.hooks.beforeHandler and the other typed hook arrays for framework lifecycle hooks. Configure native plugins in options.setup through a disposable http() lease. See configuration and migration.

Last updated on