loopbackio / loopback4-extension-grpc

gRPC Extension for LoopBack 4
Other
18 stars 8 forks source link

Required Decorators Analysis #6

Closed jonathan-casarrubias closed 6 years ago

jonathan-casarrubias commented 7 years ago

API-first (top-down) vs. code-first (bottom-up) approach, how to provide protobuf metadata - think of @api and @get decorators for REST

https://github.com/strongloop/loopback-next/issues/582

As developer, I want be able to use TypeScript decorators as an option to add proto services.

In order to follow a naming convention from the official gRPC module, I propose to use addProtoService name for this decorator, so it is easier for people coming to LB4 and that already knows gRPC to ramp up

jonathan-casarrubias commented 7 years ago

If we want to support microservices oriented architecture... This might be a good implementation

@gRPCService({ host: ‘’, port: 9000, proto: '' })
class MyController {
    @rpc()
    sayHello(HelloRequest): HelloResponse {}
}
jonathan-casarrubias commented 6 years ago

Discussed and Landed on PR #8

/**
* Setup gRPC MicroService
**/
class Greeter implements GreeterInterface {
  @grpc()
  SayHello(request: HelloRequest): HelloReply {
    return {message: `hello ${request.name}`};
  }
}