1
00:00:00,450 --> 00:00:02,070
Instructor: And the last web API

2
00:00:02,070 --> 00:00:04,620
we will talk about is gRPC.

3
00:00:04,620 --> 00:00:07,200
GRPC was developed by Google in 2015

4
00:00:07,200 --> 00:00:08,610
and what you need to know about it

5
00:00:08,610 --> 00:00:10,950
is that it is based on HTTP/2.

6
00:00:10,950 --> 00:00:14,340
Now, if you're not familiar with HTTP/2 that's fine.

7
00:00:14,340 --> 00:00:16,320
The most important thing that you need to know

8
00:00:16,320 --> 00:00:20,340
about this protocol is that it allows two ways streaming,

9
00:00:20,340 --> 00:00:24,000
meaning instead of a request and then a response

10
00:00:24,000 --> 00:00:26,070
we can implement a duplex,

11
00:00:26,070 --> 00:00:29,070
meaning the server can send messages to the client

12
00:00:29,070 --> 00:00:31,350
and not only the other way around.

13
00:00:31,350 --> 00:00:34,890
GRPC uses protobuf as its transport mechanism

14
00:00:34,890 --> 00:00:36,990
instead of XML or JSON.

15
00:00:36,990 --> 00:00:40,530
Protobuf is a serialization protocol developed by Google

16
00:00:40,530 --> 00:00:43,410
and it allows different development platforms

17
00:00:43,410 --> 00:00:46,380
such as .NET or Java to communicate between them

18
00:00:46,380 --> 00:00:48,330
using code generators

19
00:00:48,330 --> 00:00:51,420
that read the protobuf protocol and message

20
00:00:51,420 --> 00:00:54,753
and generate classes that are compliant with the data.

21
00:00:55,680 --> 00:00:58,260
Because gRPC is based on HTTP/2

22
00:00:58,260 --> 00:01:01,050
it supports bidirectional and streaming messaging

23
00:01:01,050 --> 00:01:01,883
which is something

24
00:01:01,883 --> 00:01:05,580
that neither REST nor GraphQL can support

25
00:01:05,580 --> 00:01:08,040
since they are based on HTTP/1.

26
00:01:08,040 --> 00:01:10,770
So here is a short example of gRPC.

27
00:01:10,770 --> 00:01:14,250
As you can see, we have a service called HelloService

28
00:01:14,250 --> 00:01:18,570
which accepts HelloRequest and returns HelloResponse.

29
00:01:18,570 --> 00:01:20,746
And you can see the structure of HelloRequest

30
00:01:20,746 --> 00:01:21,579
and HelloResponse in this code.

31
00:01:22,530 --> 00:01:25,530
And as you can see, it's a very simple object,

32
00:01:25,530 --> 00:01:29,850
nothing fancy, no JSON, no XML, nothing at all.

33
00:01:29,850 --> 00:01:32,250
GRPC takes care of all serialization

34
00:01:32,250 --> 00:01:34,110
of the request and the response,

35
00:01:34,110 --> 00:01:35,960
and you don't need to worry about it.

36
00:01:37,320 --> 00:01:39,750
So what you need to know about gRPC

37
00:01:39,750 --> 00:01:44,750
is in contrast to GraphQL the performance of gRPC are great.

38
00:01:44,790 --> 00:01:47,310
Again, because it is based on HTTP/2

39
00:01:47,310 --> 00:01:49,860
which is a very performant protocol

40
00:01:49,860 --> 00:01:53,340
then gRPC can provide a very good performance.

41
00:01:53,340 --> 00:01:57,570
But gRPC is not widely used yet, it's not very popular,

42
00:01:57,570 --> 00:01:59,730
and part of it is because that HTTP/2

43
00:01:59,730 --> 00:02:02,070
is still not very popular.

44
00:02:02,070 --> 00:02:04,950
In addition, it requires specialized libraries

45
00:02:04,950 --> 00:02:07,200
at both ends because of protobuf.

46
00:02:07,200 --> 00:02:09,750
We said before that in order to use protobuf

47
00:02:09,750 --> 00:02:12,360
you need to have code generators at both ends

48
00:02:12,360 --> 00:02:14,850
to serialize the protocol to classes

49
00:02:14,850 --> 00:02:16,920
in the platform you are using.

50
00:02:16,920 --> 00:02:20,340
So this is another thing that you need to take into account

51
00:02:20,340 --> 00:02:21,573
when using gRPC.

