Lesson 52 of 60
GoBuilding a Microservice with gRPC
30 minutes
Course progress87%
gRPC Basics
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
Install protobuf tools:
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Define a service (proto/todo.proto)
syntax = "proto3";
package todo;
service TodoService {
rpc Create (CreateRequest) returns (CreateResponse);
rpc List (ListRequest) returns (ListResponse);
}
message Todo { int32 id = 1; string title = 2; bool done = 3; }
message CreateRequest { string title = 1; }
message CreateResponse { Todo todo = 1; }
message ListRequest {}
message ListResponse { repeated Todo todos = 1; }