mirror of https://github.com/grpc/grpc-web.git
				
				
				
			Adding some docs on interceptors. (#1370)
This commit is contained in:
		
							parent
							
								
									3cd7e0d434
								
							
						
					
					
						commit
						49d3b70868
					
				
							
								
								
									
										23
									
								
								README.md
								
								
								
								
							
							
						
						
									
										23
									
								
								README.md
								
								
								
								
							|  | @ -104,8 +104,8 @@ typings file will also be generated for the protobuf messages and service stub. | ||||||
| in TypeScript. See **TypeScript Support** below for information on how to | in TypeScript. See **TypeScript Support** below for information on how to | ||||||
| generate TypeScript files. | generate TypeScript files. | ||||||
| 
 | 
 | ||||||
| **Note: The `commonjs+dts` and `typescript` styles are only supported by | > **Note:** The `commonjs+dts` and `typescript` styles are only supported by | ||||||
| `--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`.** | `--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`. | ||||||
| 
 | 
 | ||||||
| ### Wire Format Mode | ### Wire Format Mode | ||||||
| 
 | 
 | ||||||
|  | @ -294,9 +294,14 @@ call.on('status', (status: grpcWeb.Status) => { | ||||||
| 
 | 
 | ||||||
| ### (Option) Using Promises (Limited features) | ### (Option) Using Promises (Limited features) | ||||||
| 
 | 
 | ||||||
| NOTE: It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used. | > **NOTE:** It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used. | ||||||
| 
 | 
 | ||||||
| ```ts | ```ts | ||||||
|  | // Create a Promise client instead | ||||||
|  | const echoService = new EchoServicePromiseClient('http://localhost:8080', null, null); | ||||||
|  | 
 | ||||||
|  | ... (same as above) | ||||||
|  | 
 | ||||||
| this.echoService.echo(request, {'custom-header-1': 'value1'}) | this.echoService.echo(request, {'custom-header-1': 'value1'}) | ||||||
|   .then((response: EchoResponse) => { |   .then((response: EchoResponse) => { | ||||||
|     console.log(`Received response: ${response.getMessage()}`); |     console.log(`Received response: ${response.getMessage()}`); | ||||||
|  | @ -308,6 +313,18 @@ this.echoService.echo(request, {'custom-header-1': 'value1'}) | ||||||
| For the full TypeScript example, see | For the full TypeScript example, see | ||||||
| [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. | [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. | ||||||
| 
 | 
 | ||||||
|  | ## Custom Interceptors | ||||||
|  | 
 | ||||||
|  | Custom interceptors can be implemented and chained, which could be useful for features like auth, retries, etc. | ||||||
|  | 
 | ||||||
|  | There are 2 types of interceptors ([interfaces](https://github.com/grpc/grpc-web/blob/3cd7e0d43493d4694fed78400e4ad78031d70c09/packages/grpc-web/index.d.ts#L55-L65)): | ||||||
|  | 
 | ||||||
|  | - `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. | ||||||
|  | - `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. | ||||||
|  | 
 | ||||||
|  | For more details, see [this blog post](https://grpc.io/blog/grpc-web-interceptor/). | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| ## Ecosystem | ## Ecosystem | ||||||
| 
 | 
 | ||||||
| ### Proxy Interoperability | ### Proxy Interoperability | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue