1
00:00:00,480 --> 00:00:01,313
Memi: Okay,

2
00:00:01,313 --> 00:00:03,450
so, we've talked about API,

3
00:00:03,450 --> 00:00:05,460
about web APIs,

4
00:00:05,460 --> 00:00:07,470
we talked about the different types

5
00:00:07,470 --> 00:00:08,700
of web API,

6
00:00:08,700 --> 00:00:11,910
and now it's time for REST.

7
00:00:11,910 --> 00:00:14,463
So, what exactly is REST?

8
00:00:15,450 --> 00:00:16,560
As mentioned earlier,

9
00:00:16,560 --> 00:00:17,880
REST is an acronym,

10
00:00:17,880 --> 00:00:22,770
stands for "Representational State Transfer".

11
00:00:22,770 --> 00:00:24,030
Now at this point,

12
00:00:24,030 --> 00:00:25,650
you probably scratch your head

13
00:00:25,650 --> 00:00:26,917
and ask yourself,

14
00:00:26,917 --> 00:00:28,080
"What the?"

15
00:00:28,080 --> 00:00:30,510
Well, hell, yeah,

16
00:00:30,510 --> 00:00:31,470
I did it too,

17
00:00:31,470 --> 00:00:35,280
the first time I met this strange expression.

18
00:00:35,280 --> 00:00:36,840
But there is some logic in it,

19
00:00:36,840 --> 00:00:40,680
and here is an explanation in some simpler English.

20
00:00:40,680 --> 00:00:42,630
So what this definition means,

21
00:00:42,630 --> 00:00:44,283
is basically that,

22
00:00:45,120 --> 00:00:48,390
REST API enables transfer

23
00:00:48,390 --> 00:00:53,160
of representation of a resource's state.

24
00:00:53,160 --> 00:00:56,760
Now note, the utilized words;

25
00:00:56,760 --> 00:00:57,930
we are discussing here

26
00:00:57,930 --> 00:01:00,720
transfer of a

27
00:01:00,720 --> 00:01:04,290
representation of the state.

28
00:01:04,290 --> 00:01:06,483
And let's explain exactly what it means.

29
00:01:07,710 --> 00:01:11,160
Let's say, we have a client and a server;

30
00:01:11,160 --> 00:01:12,750
now as we mentioned before,

31
00:01:12,750 --> 00:01:15,060
REST, like similar web APIs,

32
00:01:15,060 --> 00:01:17,880
works in a request response model.

33
00:01:17,880 --> 00:01:20,187
So what happens is this,

34
00:01:20,187 --> 00:01:23,040
the client sends a request

35
00:01:23,040 --> 00:01:24,270
for the server,

36
00:01:24,270 --> 00:01:27,690
and asks for a resource's state.

37
00:01:27,690 --> 00:01:31,350
Now, let's understand what exactly a state is.

38
00:01:31,350 --> 00:01:33,210
So, we define state

39
00:01:33,210 --> 00:01:36,480
as the current resource properties,

40
00:01:36,480 --> 00:01:38,130
and or,

41
00:01:38,130 --> 00:01:41,283
the result of an action on the resource.

42
00:01:42,300 --> 00:01:43,350
So in our case,

43
00:01:43,350 --> 00:01:46,290
let's say that what we are looking for

44
00:01:46,290 --> 00:01:48,510
is order number 17.

45
00:01:48,510 --> 00:01:50,970
So we basically ask for the state

46
00:01:50,970 --> 00:01:52,920
of order number 17,

47
00:01:52,920 --> 00:01:56,250
which means we ask for the resource properties

48
00:01:56,250 --> 00:01:57,690
the order properties,

49
00:01:57,690 --> 00:02:00,090
such as when it was made,

50
00:02:00,090 --> 00:02:01,350
who is the user,

51
00:02:01,350 --> 00:02:04,290
what are the items in the order, and so on.

52
00:02:04,290 --> 00:02:07,263
So, this is the state of the order.

53
00:02:08,460 --> 00:02:10,830
What we get back from the server

54
00:02:10,830 --> 00:02:13,800
is a response containing the resource's

55
00:02:13,800 --> 00:02:16,440
state representation.

56
00:02:16,440 --> 00:02:20,040
So the server basically send us the resource,

57
00:02:20,040 --> 00:02:22,320
or the state of the resource,

58
00:02:22,320 --> 00:02:24,420
in some kind of representation.

59
00:02:24,420 --> 00:02:27,810
So the response represents the state,

60
00:02:27,810 --> 00:02:29,100
in some way,

61
00:02:29,100 --> 00:02:31,353
usually JSON, as we will see later.

62
00:02:33,060 --> 00:02:35,070
So, in our example,

63
00:02:35,070 --> 00:02:36,510
this is what we get;

64
00:02:36,510 --> 00:02:40,473
we get a representation of order number 17.

65
00:02:41,730 --> 00:02:43,480
Now, let's look at another example.

66
00:02:45,390 --> 00:02:48,750
Let's say, that the client sends a request

67
00:02:48,750 --> 00:02:50,760
to delete a resource.

68
00:02:50,760 --> 00:02:52,380
Before we asked to see,

69
00:02:52,380 --> 00:02:54,180
or to get the resource,

70
00:02:54,180 --> 00:02:56,850
now we ask to delete it.

71
00:02:56,850 --> 00:02:59,370
And what resource will you want to delete?

72
00:02:59,370 --> 00:03:03,000
We want to delete, again, order number 17.

73
00:03:03,000 --> 00:03:04,740
The server, this time,

74
00:03:04,740 --> 00:03:07,130
responds with, again,

75
00:03:07,130 --> 00:03:09,120
the resource's state representation

76
00:03:09,120 --> 00:03:11,130
which contains a status.

77
00:03:11,130 --> 00:03:12,843
And the status tells us

78
00:03:12,843 --> 00:03:16,110
that the resource has been actually deleted

79
00:03:16,110 --> 00:03:17,520
just like we asked for.

80
00:03:17,520 --> 00:03:20,850
So these are the basic components of REST;

81
00:03:20,850 --> 00:03:22,860
we see here is the resource,

82
00:03:22,860 --> 00:03:25,620
the state, and the transfer.

83
00:03:25,620 --> 00:03:29,160
The transfer is the transfer of the state's representation

84
00:03:29,160 --> 00:03:31,047
between the client and the server.

85
00:03:31,047 --> 00:03:33,290
The state of the current properties,

86
00:03:33,290 --> 00:03:36,327
or the current state of the resource,

87
00:03:36,327 --> 00:03:38,850
and the representation is the way

88
00:03:38,850 --> 00:03:41,130
the state is represented.

89
00:03:41,130 --> 00:03:43,680
Now, all this is quite theoretical,

90
00:03:43,680 --> 00:03:45,030
what happens in the real world,

91
00:03:45,030 --> 00:03:46,110
or in other word,

92
00:03:46,110 --> 00:03:48,510
what happens when we want to implement

93
00:03:48,510 --> 00:03:50,430
an actual REST API?

94
00:03:50,430 --> 00:03:52,527
So in this case, we will use, usually,

95
00:03:52,527 --> 00:03:54,270
the HTTP protocol.

96
00:03:54,270 --> 00:03:55,943
And, how will the request

97
00:03:55,943 --> 00:03:59,370
and the response look like using HTTP?

98
00:03:59,370 --> 00:04:02,220
Well, like this,

99
00:04:02,220 --> 00:04:04,147
the request will look something like,

100
00:04:04,147 --> 00:04:07,857
"GET/api/order/17"

101
00:04:07,857 --> 00:04:10,500
and the response is a number,

102
00:04:10,500 --> 00:04:13,650
in this case 200, and "OK",

103
00:04:13,650 --> 00:04:15,420
and some kind of JSON.

104
00:04:15,420 --> 00:04:16,829
Now, later in this course,

105
00:04:16,829 --> 00:04:19,380
we will deep dive into each component of the request,

106
00:04:19,380 --> 00:04:20,213
and the response.

107
00:04:20,213 --> 00:04:21,046
So, don't worry

108
00:04:21,046 --> 00:04:24,180
if you don't understand exactly what is going on here,

109
00:04:24,180 --> 00:04:25,230
but suffice to say,

110
00:04:25,230 --> 00:04:28,140
that this is a general representation

111
00:04:28,140 --> 00:04:30,180
of the request and the response,

112
00:04:30,180 --> 00:04:32,250
over the HTTP protocol.

113
00:04:32,250 --> 00:04:33,930
And now, let's deep dive

114
00:04:33,930 --> 00:04:37,260
into how a request and the response look like,

115
00:04:37,260 --> 00:04:38,133
in REST.

