Creating a simple hello world with gRPC

To understand the gRPC-Gateway we are going to first make a hello world gRPC service.

Defining your gRPC service using protocol buffers

Before we create a gRPC service, we should create a proto file to define what we need, here we create a file named hello_world.proto in the directory proto/helloworld/hello_world.proto.

The gRPC service is defined using Google Protocol Buffers. To learn more about how to define a service in a .proto file see their Basics tutorial. For now, all you need to know is that both the server and the client stub have a SayHello() RPC method that takes a HelloRequest parameter from the client and returns a HelloReply from the server, and that the method is defined like this:

  1. syntax = "proto3";
  2. package helloworld;
  3. // The greeting service definition
  4. service Greeter {
  5. // Sends a greeting
  6. rpc SayHello (HelloRequest) returns (HelloReply) {}
  7. }
  8. // The request message containing the user's name
  9. message HelloRequest {
  10. string name = 1;
  11. }
  12. // The response message containing the greetings
  13. message HelloReply {
  14. string message = 1;
  15. }

Next