Extrapolating a node.js client call from a grpcurl call?

Skip to first unread message

Elliot Blanchard

May 27, 2021, 9:38:06 AMMay 27
to grpc.io

I'm just getting started with gRPC and I have a basic question about making client calls via Node.js.

I've been given a working grpcurl call to an existing gRPC server in the form:

grpcurl main.company.com:9067 this.app.sdk.rpc.CompactTxStreamer/GetNetworkInfo

What is the best way to work backwards from that grpcurl call to be able to make the same call using the node.js gRPC architecture? Would I create a proto file for the client that I would then call? If so, how would those parameters translate into the proto format?

Thank you for your help!

Michael Lumish

Jun 1, 2021, 5:15:55 PMJun 1
to Elliot Blanchard, grpc.io
First, assuming that that is a protobuf service, you will need to have a proto file that describes it in order to make the requests. You should be able to get that file from the service provider. Once you have that, there are two main packages for using proto files with the Node gRPC libraries: one is @grpc/proto-loader, which loads proto files at runtime, and the other is grpc-tools, which generates files that depend on the google-protobuf package. These two packages have different ways of representing proto messages: proto-loader uses plain JavaScript objects with structures matching the message definitions, while grpc-tools provides message classes with getters and setters for the different message fields. In both cases, once you load the code up with the gRPC package (we recommend @grpc/grpc-js), you will get a class this.app.rpc.CompactTxStreamer that can be constructed with a specific server address (such as "main.company.com:9067"), and the concrete object will have a method GetNetworkInfo that can be called with parameters that depend on whether the request is streaming from the client or server. The API looks like the corresponding make[Something]Request method of the Client class, but without the first three parameters.

You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/28bbad75-af29-473d-8aac-1f96265f5e65n%40googlegroups.com.
Reply all
Reply to author
0 new messages