syntax = "proto3";
package example;
message Student {
string student_id = 1;
string first_name = 2;
string last_name = 3;
string address = 4;
bool is_joined = 5;
}
PB Language Version
Package of generated code
Field Tag
Field Type
Field Name
Message Type
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
service SearchService {
rpc Search (stream SearchRequest) returns (stream SearchResponse);
}
service CustomerService {
rpc RegisterCustomer (RegisterCustomerRequest) returns (RegisterCustomerResponse) {
option (google.api.http) = {
post: "/customer"
body: "*"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Register a new Customer"
description: "Register a new Customer"
tags: "customer"
};
}
rpc GetCustomerByID (GetCustomerByIDRequest) returns (GetCustomerByIDResponse) {
option (google.api.http) = {
get: "/customer/{customer_id}"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Get an existing customer"
description: "Get an existing customer"
tags: "customer"
};
}
}
HTTP Request Metadata
Swagger Metadata
example.ProfileService.Update
user_id: "123"
email: "foo@example.com"
...
PUT /v1/user/123/profile
...
{"email": "foo@example.com", ...}
product_service.proto
generates proxy
generates stub
Reverse Proxy
Your gRPC service
API Client
grpc-gateway
protoc
gRPC
REST API (JSON over HTTP)