Skip to content

Commit

Permalink
docs: add a diagram for interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Apr 23, 2019
1 parent 1cd6eea commit b1437df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/site/Interceptors.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ method invocations. There are many use cases for interceptors, such as:
- Catch/transform errors, for example, normalize error objects
- Override the method invocation, for example, return from cache

The following diagram illustrates how interceptors can be applied to the
invocation of a method on the controller class.

![Interceptors](imgs/interceptors.png)

## Basic use

### Interceptors on controllers
Expand All @@ -31,15 +36,18 @@ interceptors for corresponding routes upon API requests.
```ts
import {intercept} from '@loopback/context';

@intercept(log)
@intercept(log) // `log` is an interceptor function
export class OrderController {
@intercept('caching-interceptor')
@intercept('caching-interceptor') // `caching-interceptor` is a binding key
async listOrders(userId: string) {
// ...
}
}
```

**NOTE**: `log` and `'caching-interceptor'` are illustrated in
[Example interceptors](#example-interceptors).

It's also possible to configure global interceptors that are invoked before
method level interceptors. For example, the following code registers a global
`caching-interceptor` for all methods.
Expand Down
Binary file added docs/site/imgs/interceptors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b1437df

Please sign in to comment.