Instructor: And the last web API
we will talk about is gRPC.
GRPC was developed by Google in 2015
and what you need to know about it
is that it is based on HTTP/2.
Now, if you're not familiar with HTTP/2 that's fine.
The most important thing that you need to know
about this protocol is that it allows two ways streaming,
meaning instead of a request and then a response
we can implement a duplex,
meaning the server can send messages to the client
and not only the other way around.
GRPC uses protobuf as its transport mechanism
instead of XML or JSON.
Protobuf is a serialization protocol developed by Google
and it allows different development platforms
such as .NET or Java to communicate between them
using code generators
that read the protobuf protocol and message
and generate classes that are compliant with the data.
Because gRPC is based on HTTP/2
it supports bidirectional and streaming messaging
which is something
that neither REST nor GraphQL can support
since they are based on HTTP/1.
So here is a short example of gRPC.
As you can see, we have a service called HelloService
which accepts HelloRequest and returns HelloResponse.
And you can see the structure of HelloRequest
and HelloResponse in this code.
And as you can see, it's a very simple object,
nothing fancy, no JSON, no XML, nothing at all.
GRPC takes care of all serialization
of the request and the response,
and you don't need to worry about it.
So what you need to know about gRPC
is in contrast to GraphQL the performance of gRPC are great.
Again, because it is based on HTTP/2
which is a very performant protocol
then gRPC can provide a very good performance.
But gRPC is not widely used yet, it's not very popular,
and part of it is because that HTTP/2
is still not very popular.
In addition, it requires specialized libraries
at both ends because of protobuf.
We said before that in order to use protobuf
you need to have code generators at both ends
to serialize the protocol to classes
in the platform you are using.
So this is another thing that you need to take into account
when using gRPC.