Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the brackets {} after a gRPC method definition? [duplicate]

Tags:

grpc

In gRPC you can define a method like

service HelloService {
  rpc SayHello (HelloRequest) returns (HelloResponse);
}

or

service HelloService {
  rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

(from http://www.grpc.io/docs/guides/concepts.html#service-definition).

I've looked through the docs and there doesn't seem to be anything you can put inside the brackets. So, given that I can terminate the definition with ; what are that brackets for?

like image 978
Dmitry Minkovsky Avatar asked May 04 '17 00:05

Dmitry Minkovsky


People also ask

What does Repeated mean in Protobuf?

repeated : this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.

What does gRPC stand for?

Google Remote Procedure Call, more commonly known as gRPC, is a remote procedure call (RPC) framework that brings performance benefits and modern features to client-server applications. Like RPC, it allows you to directly call methods on other machines.

What does gRPC use for data serialization?

By default, gRPC uses Protocol Buffers, Google's mature open source mechanism for serializing structured data (although it can be used with other data formats such as JSON).

What is gRPC and how does it work?

A gRPC channel provides a connection to a gRPC server on a specified host and port. It is used when creating a client stub. Clients can specify channel arguments to modify gRPC's default behavior, such as switching message compression on or off. A channel has state, including connected and idle .


1 Answers

I'm not an expert but I will try to explain it

You can add custom options in your rpc definitions

For example if you use grpc-gateway that allows you to translate the RESTful API into gRPC

In this snippet I'm requesting the body field and the RESTful call will be in /api/{client} for example:

service Builder {
  rpc Generate(Request) returns (Response) {
    option (google.api.http) = {
      post: "/api/{Client}"
      body: "*"
    };
  }
}

You can see full reference here cloud.google.com/service-management/reference

Note: I took the reference link from the grpc-gateway repo

like image 178
Eddy Hernandez Avatar answered Sep 18 '22 15:09

Eddy Hernandez