1
00:00:00,270 --> 00:00:02,610
-: So the "get" verb,

2
00:00:02,610 --> 00:00:03,677
as we mentioned earlier

3
00:00:03,677 --> 00:00:07,530
get is used to retrieve resources.

4
00:00:07,530 --> 00:00:10,320
Which means you should never use it to add

5
00:00:10,320 --> 00:00:12,930
or update or delete resources.

6
00:00:12,930 --> 00:00:15,630
It should be used only for retrieval.

7
00:00:15,630 --> 00:00:17,970
Now it might retrieve a single resource,

8
00:00:17,970 --> 00:00:19,798
or many resource, or not at all

9
00:00:19,798 --> 00:00:23,010
if no resource is found according to the parameters.

10
00:00:23,010 --> 00:00:25,080
But again, you should never use it

11
00:00:25,080 --> 00:00:27,810
for any other types of actions.

12
00:00:27,810 --> 00:00:30,720
Now, what important to know about the "get" verb is

13
00:00:30,720 --> 00:00:33,450
that this is a default verb of the browser.

14
00:00:33,450 --> 00:00:35,280
So if you type an address in the

15
00:00:35,280 --> 00:00:38,130
in the address bar of your browsers and hit enter,

16
00:00:38,130 --> 00:00:41,310
then the browser sends a "get" action

17
00:00:41,310 --> 00:00:43,560
with the URL, of course, to the server.

18
00:00:43,560 --> 00:00:47,250
And this is what the server executes: a "get" request,

19
00:00:47,250 --> 00:00:49,034
We will see that in a minute.

20
00:00:49,034 --> 00:00:52,290
Now "get" request are usually combined

21
00:00:52,290 --> 00:00:55,110
with parameters so the server will know what

22
00:00:55,110 --> 00:00:57,540
kind of resources it should retrieve.

23
00:00:57,540 --> 00:01:00,300
It's not a mandatory and we will see some examples

24
00:01:00,300 --> 00:01:02,130
which will not use parameters,

25
00:01:02,130 --> 00:01:04,440
but sometimes you will find them.

26
00:01:04,440 --> 00:01:07,590
If you remember we mentioned earlier that a rest

27
00:01:07,590 --> 00:01:11,550
request is comprised of four components, the method

28
00:01:11,550 --> 00:01:15,540
the URL, the headers, and the body.

29
00:01:15,540 --> 00:01:18,930
Now a "get" request should not include body.

30
00:01:18,930 --> 00:01:20,400
All the information the server needs

31
00:01:20,400 --> 00:01:22,931
in order to execute the action is included

32
00:01:22,931 --> 00:01:26,100
within the method and the URL.

33
00:01:26,100 --> 00:01:29,280
The server should not require any other information

34
00:01:29,280 --> 00:01:31,380
beside the method and the URL.

35
00:01:31,380 --> 00:01:35,163
Okay, and now let's demonstrate the "get" request.

36
00:01:36,192 --> 00:01:39,150
So first, remember that we say to the browser

37
00:01:39,150 --> 00:01:43,260
by default send a "get" request from the address bar.

38
00:01:43,260 --> 00:01:45,330
So let's see this happening.

39
00:01:45,330 --> 00:01:48,390
So this is a quite standard Chrome browser

40
00:01:48,390 --> 00:01:51,720
and I want to launch the developer tools.

41
00:01:51,720 --> 00:01:53,730
If you are familiar with Chrome's developer tools

42
00:01:53,730 --> 00:01:55,860
that's great and if not, nevermind

43
00:01:55,860 --> 00:01:58,110
we are not going to deep dive into them.

44
00:01:58,110 --> 00:02:00,580
So, click F15

45
00:02:01,770 --> 00:02:03,720
and you will see this small window open

46
00:02:03,720 --> 00:02:06,180
at the right hand side of the screen.

47
00:02:06,180 --> 00:02:10,740
Now, make sure that the network tab is selected

48
00:02:10,740 --> 00:02:15,740
and now go here and type whatever others you would like.

49
00:02:17,190 --> 00:02:22,190
I will go again with google.com and "enter"

50
00:02:22,950 --> 00:02:24,450
and see what's happening here.

51
00:02:25,440 --> 00:02:30,150
So what we see here is the recording of all the requests

52
00:02:30,150 --> 00:02:31,620
that the browser made.

53
00:02:31,620 --> 00:02:36,030
Of course it asked google.com and then there will some kind

54
00:02:36,030 --> 00:02:39,300
of JavaScript files and icons and images and then

55
00:02:39,300 --> 00:02:40,500
many other things.

56
00:02:40,500 --> 00:02:42,825
But we will focus only on the field request,

57
00:02:42,825 --> 00:02:44,850
which is google.com.

58
00:02:44,850 --> 00:02:49,800
So click it here and what we'll see here is a quite

59
00:02:49,800 --> 00:02:53,130
detailed description of the request and the response.

60
00:02:53,130 --> 00:02:57,390
And the thing that really interesting for us is this;

61
00:02:57,390 --> 00:03:01,567
The request method is "get", so even though the word

62
00:03:01,567 --> 00:03:05,580
"get" is not written anywhere in the, this is what

63
00:03:05,580 --> 00:03:07,890
the browser sent to the server, we can also

64
00:03:07,890 --> 00:03:10,020
see the status code, which is 200

65
00:03:10,020 --> 00:03:12,910
and we already know that 200 meaning okay

66
00:03:14,370 --> 00:03:17,040
Great, so we saw what the browser is doing.

67
00:03:17,040 --> 00:03:20,220
But what is really interesting for us is of course

68
00:03:20,220 --> 00:03:21,420
the REST API.

69
00:03:21,420 --> 00:03:25,350
So let's go again to the Beeceptor for our page

70
00:03:25,350 --> 00:03:27,390
that we built with our sub domain.

71
00:03:27,390 --> 00:03:29,550
Again, my Sub domain is API course.

72
00:03:29,550 --> 00:03:32,044
You probably selected other Sub domains

73
00:03:32,044 --> 00:03:35,910
and we will start building a new API.

74
00:03:35,910 --> 00:03:40,350
So again, let's go here to the mocking rules and click it

75
00:03:40,350 --> 00:03:43,110
and we will create new rule.

76
00:03:43,110 --> 00:03:44,710
So what are we going to do here?

77
00:03:45,750 --> 00:03:47,790
With the method we are going to stay with "get",

78
00:03:47,790 --> 00:03:50,640
this is a verb that we are discussing in this lecture.

79
00:03:50,640 --> 00:03:55,440
And here in the API URL I will define the following API.

80
00:03:55,440 --> 00:03:59,700
So this will be forward slash API forward slash order

81
00:04:02,279 --> 00:04:07,279
and I'll just modify the response body to be "order"

82
00:04:11,880 --> 00:04:14,940
And We will create another object here,

83
00:04:14,940 --> 00:04:16,360
another JSON object

84
00:04:18,269 --> 00:04:20,072
and we'll call it,

85
00:04:21,547 --> 00:04:22,680
we'll call this one, sorry

86
00:04:22,680 --> 00:04:25,100
order date and make it

87
00:04:30,810 --> 00:04:34,083
12/12/2018.

88
00:04:36,240 --> 00:04:41,240
And order user, which is a user that made the order.

89
00:04:43,650 --> 00:04:47,310
And let's say it was user number 17 and close this one.

90
00:04:47,310 --> 00:04:48,633
Close this one, great,

91
00:04:50,460 --> 00:04:51,660
and let's save the rule.

92
00:04:51,660 --> 00:04:56,660
But before it, just remember this part forward slash API

93
00:04:56,790 --> 00:04:58,770
forward slash order.

94
00:04:58,770 --> 00:05:03,580
And save all, Great, let's close this window

95
00:05:05,430 --> 00:05:10,430
again copy this part so you will be able to access API.

96
00:05:10,470 --> 00:05:11,970
So control C.

97
00:05:11,970 --> 00:05:15,900
And now let's go to Postman right here.

98
00:05:15,900 --> 00:05:19,233
And I bring it from auto screen.

99
00:05:20,700 --> 00:05:24,360
So here I've already have the prefix

100
00:05:24,360 --> 00:05:28,803
so all I need to do is simply change test to order.

101
00:05:29,836 --> 00:05:34,836
So this is the API that we created in Beeceptor and send.

102
00:05:38,280 --> 00:05:39,870
And this is what we've got

103
00:05:39,870 --> 00:05:42,986
and this is exactly what we were expecting.

104
00:05:42,986 --> 00:05:45,360
If you got anything different than that

105
00:05:45,360 --> 00:05:48,210
some kind of error message or things like that

106
00:05:48,210 --> 00:05:52,170
then be sure that you used the same verb.

107
00:05:52,170 --> 00:05:55,770
It would be "get" make sure that the URL is correct

108
00:05:55,770 --> 00:06:00,300
and also, double check the JSON that you typed in Beeceptor.

109
00:06:00,300 --> 00:06:03,180
So just so we will remember it,

110
00:06:03,180 --> 00:06:05,640
this is what you should see in the response body.

111
00:06:05,640 --> 00:06:09,450
If you see anything else, then maybe the JSON is malformed

112
00:06:09,450 --> 00:06:12,330
and can't be validated and returned.

113
00:06:12,330 --> 00:06:13,163
Okay, great.

114
00:06:13,163 --> 00:06:15,780
So we've built our first "get" request.

115
00:06:15,780 --> 00:06:18,090
Now there is some limitation to get requests.

116
00:06:18,090 --> 00:06:22,230
For example, the length of a "get" request is limited.

117
00:06:22,230 --> 00:06:26,190
Now the limit itself is varied by browser and by server.

118
00:06:26,190 --> 00:06:28,350
So there is no definite number

119
00:06:28,350 --> 00:06:31,440
that all servers and browsers are compliant with,

120
00:06:31,440 --> 00:06:35,748
but it usually somewhere around 1000 or 2000 characters.

121
00:06:35,748 --> 00:06:38,490
Now let's demonstrate what's happening

122
00:06:38,490 --> 00:06:40,901
when sending a too long "get" request.

123
00:06:40,901 --> 00:06:43,720
So I do something like this

124
00:06:45,053 --> 00:06:50,053
and I'll take it and copy it to make it quicker.

125
00:06:50,212 --> 00:06:53,370
I have no idea how many characters are here

126
00:06:53,370 --> 00:06:54,963
but there are definitely a lot.

127
00:06:59,220 --> 00:07:04,140
And let's add this again and send.

128
00:07:06,720 --> 00:07:08,850
Okay. And now look at the response

129
00:07:08,850 --> 00:07:12,671
that we've got from the server.

130
00:07:12,671 --> 00:07:14,700
We've got a very nicely formatted message

131
00:07:14,700 --> 00:07:17,910
actually HTML formatted, and it basically tells us

132
00:07:17,910 --> 00:07:21,210
that the URI is too large.

133
00:07:21,210 --> 00:07:23,310
And you can also see here the status code.

134
00:07:23,310 --> 00:07:27,540
Status code is 4 1 4, meaning the URI is too large.

135
00:07:27,540 --> 00:07:29,010
So you should always keep in mind

136
00:07:29,010 --> 00:07:32,190
that there is a limit for the length of the "get" request

137
00:07:32,190 --> 00:07:35,163
and make sure not to send too long requests.

138
00:07:36,780 --> 00:07:38,581
Now this limit begs a question,

139
00:07:38,581 --> 00:07:42,990
what happens when the query contains too many parameters?

140
00:07:42,990 --> 00:07:44,945
For example, let's say I have a list

141
00:07:44,945 --> 00:07:49,740
of items of 2000 items and I want to retrieve them.

142
00:07:49,740 --> 00:07:52,740
So in this case, I will have to send this list

143
00:07:52,740 --> 00:07:55,200
this giant list to the server

144
00:07:55,200 --> 00:07:58,350
in order for it to send me back the items.

145
00:07:58,350 --> 00:08:02,190
However, this giant list with all its 2000 items

146
00:08:02,190 --> 00:08:05,040
is simply too long to be sent using "get".

147
00:08:05,040 --> 00:08:06,900
So what should I do in this case?

148
00:08:06,900 --> 00:08:10,020
Well, in this case we can use the post verb

149
00:08:10,020 --> 00:08:12,210
which we will talk about in a minute.

150
00:08:12,210 --> 00:08:13,043
So it's true

151
00:08:13,043 --> 00:08:16,800
that post is not targeted towards retrieval actions

152
00:08:16,800 --> 00:08:19,890
but in this specific case we don't have any other choice.

153
00:08:19,890 --> 00:08:23,550
So when dealing with a long list of parameters

154
00:08:23,550 --> 00:08:27,633
which can't be sent using a get is an use POST.

