Skip to content

Commit 49d3b70

Browse files
authored
Adding some docs on interceptors. (#1370)
1 parent 3cd7e0d commit 49d3b70

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ typings file will also be generated for the protobuf messages and service stub.
104104
in TypeScript. See **TypeScript Support** below for information on how to
105105
generate TypeScript files.
106106

107-
**Note: The `commonjs+dts` and `typescript` styles are only supported by
108-
`--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`.**
107+
> **Note:** The `commonjs+dts` and `typescript` styles are only supported by
108+
`--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`.
109109

110110
### Wire Format Mode
111111

@@ -294,9 +294,14 @@ call.on('status', (status: grpcWeb.Status) => {
294294

295295
### (Option) Using Promises (Limited features)
296296

297-
NOTE: It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used.
297+
> **NOTE:** It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used.
298298
299299
```ts
300+
// Create a Promise client instead
301+
const echoService = new EchoServicePromiseClient('http://localhost:8080', null, null);
302+
303+
... (same as above)
304+
300305
this.echoService.echo(request, {'custom-header-1': 'value1'})
301306
.then((response: EchoResponse) => {
302307
console.log(`Received response: ${response.getMessage()}`);
@@ -308,6 +313,18 @@ this.echoService.echo(request, {'custom-header-1': 'value1'})
308313
For the full TypeScript example, see
309314
[ts-example/client.ts](net/grpc/gateway/examples/echo/ts-example/client.ts) with the [instructions](net/grpc/gateway/examples/echo/ts-example) to run.
310315

316+
## Custom Interceptors
317+
318+
Custom interceptors can be implemented and chained, which could be useful for features like auth, retries, etc.
319+
320+
There are 2 types of interceptors ([interfaces](https://github.com/grpc/grpc-web/blob/3cd7e0d43493d4694fed78400e4ad78031d70c09/packages/grpc-web/index.d.ts#L55-L65)):
321+
322+
- `UnaryInterceptor` ([doc](https://grpc.io/blog/grpc-web-interceptor/#stream-interceptor-example), [example](https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/test/tsc-tests/client04.ts)) - Intercept Unary RPCs; can only be used with Promise clients.
323+
- `StreamInterceptor` ([doc](https://grpc.io/blog/grpc-web-interceptor/#stream-interceptor-example), [example](https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/test/tsc-tests/client03.ts)) - More versatile; can be used with regular clients.
324+
325+
For more details, see [this blog post](https://grpc.io/blog/grpc-web-interceptor/).
326+
327+
311328
## Ecosystem
312329

313330
### Proxy Interoperability

0 commit comments

Comments
 (0)