Defining a service API using Protocol Buffers
Let’s demonstrate how to define a service API using the Protocol Buffers format and generate the client and server gRPC code for communication with each of our services using a proto compiler. This knowledge will help you to establish a foundation for both defining and implementing APIs for your microservices using one of the industry’s most popular communication tools.
Let’s start with our metadata service and write its API definition in the Protocol Buffers schema language.
Open the api/movie.proto
file that we created in the previous chapter and add the following to it:
service MetadataService {
rpc GetMetadata(GetMetadataRequest) returns (GetMetadataResponse);
rpc PutMetadata(PutMetadataRequest) returns (PutMetadataResponse);
}
message GetMetadataRequest {
string movie_id = 1;
}
message GetMetadataResponse {
&...