gRPC is an open-source remote process call system developed at Google in 2015.The supporting programming languages like C++, Java (+ Android), Objective-C (iOS), Python, Ruby, Go, C#, NodeJS and others.It uses HTTP / 2 to transfer binary messages and through a default protocol buffer as an interface definition language (IDL) to describe the service interface and the composition of the messages.
service Greeter
{
rpcSayHi (HiRequest) returns (HiReply) {}
}
message HiRequest {
string name = 1;
}
message HiReply {
string message = 1;
}
The gRPC defines two types of service methods,
- Unary RPCs, where the client sends a request to the server and receives the same response.
- Client streaming RPCs wherever the client writes a sequence of messages and sends them to the server, using the re-provided stream.
- Bidirectional streaming RPC where the client and the server exchange messages in both directions.
- Server Streaming RPC wherever the client sends a call for participation message to the server and receives a sequence of replies.
If we compare gRPC to Web API, differences are,
-
The Web API is based on the REST architecture where the gRPC proposes RPC model, a model where a remote process is demanded on the server as a client.
-
The Web API uses HTTP for transport while the gRPC uses HTTP / 2.
-
The data exchanged by the Web API is a human readable format (especially JSON), while the gRPC uses a compact binary format.