You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `@loopback/grpc` component enables LoopBack 4 as a [gRPC](https://grpc.io/) Server. Also it provides with a gRPC decorator to define your RPC Method implementations from your Application Controllers.
8
8
9
+
### Features
10
+
11
+
- Handles unary, client streaming, server streaming and bidirectional streaming calls
12
+
- Provides options for TLS and mTLS
13
+
9
14
## Installation
10
15
11
16
Install the `@loopback/grpc` component in your LoopBack 4 Application.
console.log(formatWithColor('Generating proto.ts files from *.proto...', 33));
107
+
generator.execute();
108
+
console.log(formatWithColor('All proto.ts files have been generated', 32));
109
+
```
110
+
111
+
## gRPC Controller
112
+
113
+
The `@loopback/grpc` component provides you with a handy decorator to implement gRPC Methods within your LoopBack controllers. The decorator will automatically map the correct calls from the file descriptor, the method name and the controller name. If you want an other suffix than `(Ctrl|Controller)`, you can use the argument `controllerNameRegex`.
114
+
115
+
`app/controllers/greeter.controller.ts`
116
+
117
+
```ts
118
+
import {
119
+
TestRequest,
120
+
TestResponse,
121
+
Greeter,
122
+
protoMetadata,
123
+
} from'../protos-ts/greeter';
124
+
125
+
classGreeterCtrlimplementsGreeter {
126
+
// Tell LoopBack that this is a Service RPC implementation
Decorators provide annotations for class methods and arguments. Decorators use the form `@decorator` where `decorator` is the name of the function that will be called at runtime.
@@ -8,51 +7,62 @@ Decorators provide annotations for class methods and arguments. Decorators use t
8
7
This decorator allows you to annotate a `Controller` class. The decorator will setup a GRPC Service.
9
8
10
9
**Example**
11
-
````js
10
+
11
+
```js
12
12
/**
13
-
* Setup gRPC MicroService
14
-
**/
15
-
//myproject/controllers/greeter/Greeter.ts
16
-
//myproject/controllers/greeter/greeter.proto
17
-
//myproject/controllers/greeter/greeter.proto.ts
13
+
* Setup gRPC MicroService
14
+
**/
15
+
//myproject/controllers/greeter.controller.ts
16
+
//myproject/protos/greeter/greeter.proto
17
+
//myproject/protos-ts/greeter/greeter.ts
18
18
//Note: greeter.proto.ts is automatically generated from
0 commit comments