cablelabs / lpwanserver

LPWAN Provisioning & Management Server
https://lpwanserver.com
Apache License 2.0
37 stars 11 forks source link

gRPC API vertical slice #320

Closed rhythnic closed 5 years ago

rhythnic commented 5 years ago

Implement for User and Email services:

rhythnic commented 5 years ago

Exposing a REST proxy in node for a gRPC server is difficult. gRPC-gateway, the default solution, only generates Golang code. The equivalent solution in Nodejs, grpc-dynamic-gateway, only supports dynamic proto loading. There's a bug in protobuf.js, used by proto-loader. Effectively, this means no dynamic gRPC generation for any protos that import common google types. There's no indication the bug will be fixed soon.

When creating the gRPC server from JavaScript code statically generated from protos, there is this bug, which is about the code attempting to import modules at the wrong file path. That module was in regards to the annotations, so a statically generated service could work as long as it didn't have the annotations. There's a build-time hack, but it's technical debt.

For a greenfield project built on protobufs, Golang is a better choice for the implementation language. Golang seems to be the ecosystem with the least amount of friction when using protocol buffers. You could also run the Golang gRPC proxy as a separate service, there would be two parallel builds, one for the JavaScript app and one for the Golang REST proxy.

For Node.js, OpenAPI seems like a better path, until the bugs are worked out. Both of the bugs have been unresolved for a long time. As a compromise, a decent OpenAPI doc might be compiled from protos.