WIP: Protobuf and gRPC. The basics.

Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.” - said here.

But it’s not only about serializing data, it’s also about describing services and messages this services can produce and consume. Today, I’d like to talk about one more way of creating APIs.

Simple Math service.

Let’s define simple math service which can add couple of numbers.

This is how it might looks like. I’m not talking about a transport or endpoints or routes, but about service definition. Why it’s important? This definition is an interface “to the world” for your service. It’s how your service would be represented to end users.

// mservice.proto

syntax = "proto3";
package ms.dev.service;

service MathService {
  rpc Add(AddRequest) returns (AddResponse);

message AddRequest {
  int64 a = 1;
  int64 b = 2;

message AddResponse {
  int64 result = 1;

Here we’ve written down next things:

Pretty simple and straightforward.