gRPC & Protocol Buffers (Protobuf) Commands Matrix
The definitive gRPC and Protocol Buffers cheat sheet: protoc code generation flags, grpcurl live API inspection, proto3 message and service syntax, repeated/oneof rules, and streaming RPCs with 1-click copy.
Protoc CLI & CodeGen (4 commands)
protoc --proto_path=proto --go_out=gen --go_opt=paths=source_relative proto/user.proto
Compiles .proto files into Go structs and serialization helper functions using protoc-gen-go.
protoc --proto_path=proto --go-grpc_out=gen --go-grpc_opt=paths=source_relative proto/user.proto
Generates Go gRPC client interfaces and server stubs from service RPC definitions.
protoc --proto_path=proto --ts_out=service=grpc-web:./src/gen proto/*.proto
Compiles Protocol Buffer definitions into TypeScript types and gRPC-Web clients for frontend browser apps.
protoc --proto_path=proto --python_out=./gen --grpc_python_out=./gen proto/service.proto
Generates Python message bindings (_pb2.py) and gRPC client/server stubs (_pb2_grpc.py).
gRPCurl Inspection (4 commands)
grpcurl -plaintext localhost:50051 list
Queries a running gRPC server for all registered services using Server Reflection.
grpcurl -plaintext localhost:50051 describe user.v1.UserService
Describes all RPC methods, request types, and response types for a specified service.
grpcurl -plaintext -d '{"id": "usr_102"}' localhost:50051 user.v1.UserService/GetUser
Executes an RPC call with a JSON request payload converted on the fly to protobuf binary.
grpcurl -H "Authorization: Bearer <token>" api.production.com:443 user.v1.UserService/ListUsers
Transmits custom metadata headers (like auth bearer tokens) over secure TLS gRPC connection.
Proto3 Syntax Patterns (4 commands)
syntax = "proto3";
package auth.v1;
option go_package = "example.com/gen/auth/v1;authv1";
Standard proto3 header specifying version, logical namespace package, and language target paths.
message UserProfile {
string user_id = 1;
string email = 2;
repeated string roles = 3;
map<string, string> metadata = 4;
}
Defines scalar fields, repeated arrays, and hash maps with 1-based unique field tag numbers.
oneof authentication {
string password_hash = 10;
string oauth_token = 11;
string api_key = 12;
}
Defines mutually exclusive fields where setting one automatically clears all other fields in the oneof.
service OrderService {
rpc StreamOrders (OrderRequest) returns (stream OrderUpdate);
}
Server-streaming RPC definition where the client sends one request and receives a stream of messages.