Petra Bierleutgeb
@pbvie
Petra Bierleutgeb
@pbvie
Do we even need another approach?
* without additional tools like Swagger and friends
manual RPC
over
HTTP/JSON?
operations:
follow
unfollow
retweet
like
...
wrappers/stubs
+
=
Principles and Design
* good explanation: https://stackoverflow.com/a/31814967
message User {
uint64 id = 1;
string email = 2;
Address address = 3;
repeated Interest interests = 4;
}
message Address {
message City {
string zipCode = 1;
string name = 2;
}
uint64 id = 1;
City city = 2;
string street = 3;
}
// ...
tag numbers
service MyExampleService {
rpc MyExampleMethod(MyRequestMessage) returns (stream MyResponseMessage) {}
}
service name
method name
request param
response
streaming
/*
* Example service showing all available gRPC communication styles.
*/
service ExampleService {
rpc Unary(MyReqMsg) returns (MyRespMsg) {}
rpc ClientStreaming(stream MyReqMsg) returns (MyRespMsg) {}
rpc ServerStreaming(MyReqMsg) return (stream MyRespMsg) {}
rpc ServerStreaming(stream MyReqMsg) return (stream MyRespMsg) {}
}
syntax = "proto3";
package io.ontherocks.echo.protocol;
/*
* Simple echo service - example of unary and streaming responses.
*/
service Echo {
rpc Echo (EchoRequest) returns (EchoResponse) {}
rpc EchoStream (EchoRequest) returns (stream EchoResponse) {}
}
message EchoRequest {
string message = 1;
}
message EchoResponse {
string message = 1;
}
Demo
Technical and non-technical wins
service Evolver {
rpc Sample(Req) returns (Resp) {}
}
message SomeRequest {
string old_name = 1;
int32 counter = 2;
}
service Evolver {
rpc Sample(Req) returns (Req) {}
}
message SomeRequest {
string new_name = 1;
boolean toggle = 3;
}
SomeRequest(
new_name = "abc",
toggle = true // ignored
)
SomeRequest(
old_name = "abc", // through tag no.
counter = 0 // default
)
SomeRequest(
old_name = "abc",
counter = 7 // ignored
)
SomeRequest(
new_name = "abc", // through tag no.
toggle = false // default
)
new message to old service
old message to new service
good intro to HTTP/2: https://developers.google.com/web/fundamentals/performance/http2/
good intro to HTTP/2: https://developers.google.com/web/fundamentals/performance/http2/
supporting (legacy) clients via HTTP/JSON
service Echo {
rpc Echo (EchoRequest) returns (EchoResponse) {}
}
message EchoRequest {
string message = 1;
}
message EchoResponse {
string message = 1;
}
service Echo {
rpc Echo (EchoRequest) returns (EchoResponse) {
option (google.api.http) = {
get: "/example/echo"
};
}
}
message EchoRequest {
string message = 1;
}
message EchoResponse {
string message = 1;
}
GET /example/echo?message=HelloBerlin
aka
"final slides before beer/food"
What does the 'g' actually stand for?
Questions?