In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side, the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub (referred to as just a client in some languages) that provides the same methods as the server.
gRPC clients and servers can communicate no matter what programming languages they're written in. For instance, you can easily create gRPC servers in C++ and clients in Ruby/Python.
gRPC uses (Protocol Buffers, aka. Protobuf)(https://github.com/google/protobuf), for data serialization.
This is how you can define a service in gRPC
service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}
message HelloRequest {
string greeting = 1;
}
message HelloResponse {
string reply = 1;
}
gRPC lets you define four kinds of service method:
The client sends a single request to the server and gets a single response back, just like a normal function call.
rpc SayHello(HelloRequest) returns (HelloResponse){
}
The client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages.
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse){
}
The client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them and return its response.
rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse) {
}
Both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved.
rpc BidiHello(stream HelloRequest) returns (stream HelloResponse){
}
The following authentication mechanisms are built-in to gRPC:
-
SSL/TLS: gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the server, and to encrypt all the data exchanged between the client and the server.
-
Token-based authentication with Google
The transportation of gRPC is based on HTTP/2.
gRPC provides multiple built-in errors. See at: http://www.grpc.io/docs/guides/error.html#error-status-codes
- gRPC Guides - http://www.grpc.io/docs/guides/