UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

49 lines (33 loc) 1.62 kB
--- lang: en title: 'API docs: context.intercept' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context permalink: /doc/en/lb4/apidocs.context.intercept.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [intercept](./context.intercept.md) ## intercept() function Decorator function `@intercept` for classes/methods to apply interceptors. It can be applied on a class and its public methods. Multiple occurrences of `@intercept` are allowed on the same target class or method. The decorator takes a list of `interceptor` functions or binding keys. <b>Signature:</b> ```typescript export declare function intercept(...interceptorOrKeys: InterceptorOrKey[]): (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | interceptorOrKeys | [InterceptorOrKey](./context.interceptororkey.md)<!-- -->\[\] | One or more interceptors or binding keys that are resolved to be interceptors | <b>Returns:</b> (target: any, method?: string \| undefined, methodDescriptor?: TypedPropertyDescriptor&lt;any&gt; \| undefined) =&gt; any ## Example ```ts @intercept(log, metrics) class MyController { @intercept('caching-interceptor') @intercept('name-validation-interceptor') greet(name: string) { return `Hello, ${name}`; } } ```