Skip to content

02 Define the proto

Create greeter.proto at the root of your project:

proto
// greeter.proto
syntax = "proto3";

package greeter;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

What each part does:

PartPurpose
syntax = "proto3"Use the modern proto3 dialect (required fields removed, defaults are zero-values).
package greeterNamespace — you'll reference it as proto.Greeter after loading.
service GreeterDeclares the RPC service with one unary method.
rpc SayHelloA unary call: one request, one response.
HelloRequestCarries a single name string (field number 1).
HelloReplyReturns a single message string (field number 1).

Field numbers (the = 1 parts) identify fields in the binary encoding. Once published, never renumber them.

Next: 03 Load the proto