1
00:00:00,556 --> 00:00:02,055
- [Instructor] Hi and
welcome back to the course.

2
00:00:02,055 --> 00:00:05,530
In this video we're going
to look at HTTP Verbs.

3
00:00:05,530 --> 00:00:08,707
HTTP is one of the most popular protocols,

4
00:00:08,707 --> 00:00:12,065
one of the most popular ways of creating

5
00:00:12,065 --> 00:00:14,288
interactions and allowing interactions

6
00:00:14,288 --> 00:00:18,077
between two internet connected elements

7
00:00:18,077 --> 00:00:21,660
such as your computer
and another computer.

8
00:00:23,901 --> 00:00:28,393
The first thing we wanna look
at is what is a web server?

9
00:00:28,393 --> 00:00:31,335
This course is all about
creating web servers, so I think

10
00:00:31,335 --> 00:00:34,806
that kinda gives you a bit of a hint.

11
00:00:34,806 --> 00:00:36,612
Now, a web server has many definitions.

12
00:00:36,612 --> 00:00:38,431
One of them is it's a piece of hardware

13
00:00:38,431 --> 00:00:40,014
like a computer is.

14
00:00:41,046 --> 00:00:45,484
Another definition is that
it is a piece of software

15
00:00:45,484 --> 00:00:47,815
and this piece of software
is designed to accept

16
00:00:47,815 --> 00:00:50,157
incoming web requests.

17
00:00:50,157 --> 00:00:54,324
Now, if this sounds like
Chinese which I hope it doesn't,

18
00:00:55,873 --> 00:00:57,831
it doesn't sound completely foreign.

19
00:00:57,831 --> 00:01:00,826
Let's have a look at what
web requests are as well.

20
00:01:00,826 --> 00:01:03,076
But first, a quick example.

21
00:01:03,953 --> 00:01:06,286
Google has many web servers.

22
00:01:07,524 --> 00:01:11,691
And whenever we go to
http://www.google.com

23
00:01:13,799 --> 00:01:17,207
in our browser, such as
Google Chrome or Safari,

24
00:01:17,207 --> 00:01:18,461
what we're doing is
we're sending something

25
00:01:18,461 --> 00:01:20,901
to one of their web servers.

26
00:01:20,901 --> 00:01:22,412
We don't know which web
server, but we know it's

27
00:01:22,412 --> 00:01:23,412
one of them.

28
00:01:24,969 --> 00:01:26,663
And when we send something
to the web server

29
00:01:26,663 --> 00:01:30,731
the web server can then
decide to respond back.

30
00:01:30,731 --> 00:01:34,527
It may not respond, as
we'll see in a moment.

31
00:01:34,527 --> 00:01:37,989
So, what is it that we
send to these web servers?

32
00:01:37,989 --> 00:01:42,156
Well, when we go to http://www.google.com

33
00:01:44,212 --> 00:01:46,027
we send exactly the
following, this is what

34
00:01:46,027 --> 00:01:47,694
the web server sees.

35
00:01:50,455 --> 00:01:53,254
So, when a user such
as ourselves, accesses

36
00:01:53,254 --> 00:01:56,093
the Google home page one
of their servers somewhere

37
00:01:56,093 --> 00:01:59,512
receives this piece of information.

38
00:01:59,512 --> 00:02:03,679
Get/http/1.1, and the
host is www.google.com.

39
00:02:08,152 --> 00:02:10,360
So, what does this mean?

40
00:02:10,360 --> 00:02:13,675
Well, this is what's
called the get request

41
00:02:13,675 --> 00:02:17,888
and the server just
sees that, get/http/1.1

42
00:02:17,888 --> 00:02:20,888
and the host name which is not here.

43
00:02:22,220 --> 00:02:25,062
So, the get is called a verb.

44
00:02:25,062 --> 00:02:28,560
It tells the server to
some extent, what we think

45
00:02:28,560 --> 00:02:31,119
the server is going to return.

46
00:02:31,119 --> 00:02:34,036
So, what is expected of the server.

47
00:02:35,471 --> 00:02:38,772
The slash is the path,
which is what we want

48
00:02:38,772 --> 00:02:41,005
out of the server.

49
00:02:41,005 --> 00:02:44,544
Finally, http/1.1 is
the protocol and this is

50
00:02:44,544 --> 00:02:46,753
the most popular http protocol, but now

51
00:02:46,753 --> 00:02:49,769
we're also experimenting
with http/2 as well

52
00:02:49,769 --> 00:02:53,727
which is a faster and
more efficient version.

53
00:02:53,727 --> 00:02:55,453
So, this is really all the server sees

54
00:02:55,453 --> 00:02:57,963
and when we create our own
web server applications

55
00:02:57,963 --> 00:03:01,463
we're going to see something very similar.

56
00:03:02,752 --> 00:03:04,042
So, what?

57
00:03:04,042 --> 00:03:05,625
Is that everything?

58
00:03:06,554 --> 00:03:07,742
Well actually, yeah.

59
00:03:07,742 --> 00:03:10,427
That's all the server sees

60
00:03:10,427 --> 00:03:14,296
and the server sees that
and then there's some code

61
00:03:14,296 --> 00:03:17,499
and the code is what the
server runs on and that allows

62
00:03:17,499 --> 00:03:21,666
it to make a decision as to
what it's going to respond with.

63
00:03:22,550 --> 00:03:24,684
So, different servers may
interpret the get request

64
00:03:24,684 --> 00:03:29,221
in many different ways and
they'll respond differently.

65
00:03:29,221 --> 00:03:32,670
For example, the server
may give you an error

66
00:03:32,670 --> 00:03:35,249
if the path is not found.

67
00:03:35,249 --> 00:03:38,034
In this case the forward slash.

68
00:03:38,034 --> 00:03:40,738
It may give you an error
if http is not supported.

69
00:03:40,738 --> 00:03:42,723
For example, if it's a mail
server and only supports

70
00:03:42,723 --> 00:03:46,140
SMTP, or if it's an FDP server and so on.

71
00:03:47,285 --> 00:03:48,582
It may give you an error if a server

72
00:03:48,582 --> 00:03:50,665
is currently unavailable.

73
00:03:51,574 --> 00:03:53,548
But, it may not also give you
errors, it may also give you

74
00:03:53,548 --> 00:03:57,323
useful stuff such as a HTML code, which is

75
00:03:57,323 --> 00:04:00,716
what it normally does at
least in Google's case.

76
00:04:00,716 --> 00:04:03,678
It may also give you some text.

77
00:04:03,678 --> 00:04:05,833
It may give you nothing if
the server is not configured

78
00:04:05,833 --> 00:04:07,906
to give you anything, then it just won't

79
00:04:07,906 --> 00:04:09,823
give you anything back.

80
00:04:11,527 --> 00:04:12,819
So, what else?

81
00:04:12,819 --> 00:04:16,525
Well, going to any page with
your browser such as Chrome

82
00:04:16,525 --> 00:04:18,943
or Safari or Firefox
will always do the same.

83
00:04:18,943 --> 00:04:21,046
It's always going to do a get request.

84
00:04:21,046 --> 00:04:23,361
So, here's a couple examples.

85
00:04:23,361 --> 00:04:25,858
For example, going to
the login on Twitter page

86
00:04:25,858 --> 00:04:30,315
which is https://twitter.com/login.

87
00:04:30,315 --> 00:04:34,403
That performs the get request get/login.

88
00:04:34,403 --> 00:04:39,066
Ad you can see, up to
the .com is the host name

89
00:04:39,066 --> 00:04:41,397
and anything after that is the path,

90
00:04:41,397 --> 00:04:42,838
what we are requesting.

91
00:04:42,838 --> 00:04:47,279
So, in this case, the host
is https://twitter.com

92
00:04:47,279 --> 00:04:51,891
and the path is /login,
which is what comes after.

93
00:04:51,891 --> 00:04:55,118
Similarly for this other
page, we are requesting

94
00:04:55,118 --> 00:04:57,820
/download/mac and you can
see that Google Chrome

95
00:04:57,820 --> 00:05:01,380
has a nice colour and it
tells us what the different

96
00:05:01,380 --> 00:05:03,679
parts are just by looking
at the colour of it.

97
00:05:03,679 --> 00:05:05,801
A lot of browers don't
do the same, which is

98
00:05:05,801 --> 00:05:08,009
a bit of a shame.

99
00:05:08,009 --> 00:05:10,555
And finally, google.co.uk, the host is

100
00:05:10,555 --> 00:05:15,490
https://www.google.co.uk and the path

101
00:05:15,490 --> 00:05:18,740
in this case is just the forward slash.

102
00:05:19,674 --> 00:05:21,563
By now you may have realised
that the forward slash

103
00:05:21,563 --> 00:05:25,480
is the root, the sort of
home page if you wish.

104
00:05:26,567 --> 00:05:29,397
And so, when we just go
to a page that normally

105
00:05:29,397 --> 00:05:32,037
just requests the home
page and then normally

106
00:05:32,037 --> 00:05:34,454
there's just a forward slash.

107
00:05:36,081 --> 00:05:38,185
So, the differences
between these three servers

108
00:05:38,185 --> 00:05:41,315
aren't just on what the
server responds with.

109
00:05:41,315 --> 00:05:44,000
Every server sees it,
essentially identical requests

110
00:05:44,000 --> 00:05:46,808
requesting different paths granted.

111
00:05:46,808 --> 00:05:48,833
But, the only difference
is what the server

112
00:05:48,833 --> 00:05:50,660
responds with and in Twitter's
case they respond with

113
00:05:50,660 --> 00:05:53,756
the Twitter login HTML page and the

114
00:05:53,756 --> 00:05:55,751
get scm case they respond with the get scm

115
00:05:55,751 --> 00:05:59,075
downloads for Mac HTML
page and in Google's case

116
00:05:59,075 --> 00:06:02,544
they respond with the
main Google home page

117
00:06:02,544 --> 00:06:06,548
which seems fairly obvious,
but really when we create

118
00:06:06,548 --> 00:06:09,375
our own web servers that's,
we're gonna see exactly

119
00:06:09,375 --> 00:06:11,459
the same as they do,
but we're gonna respond

120
00:06:11,459 --> 00:06:14,197
with slightly different HTML code.

121
00:06:14,197 --> 00:06:15,546
So, what I want you to realise is there's

122
00:06:15,546 --> 00:06:17,322
no magic going on here.

123
00:06:17,322 --> 00:06:19,241
All the server is seeing is
the piece of data coming in

124
00:06:19,241 --> 00:06:21,912
and then it's responding
with another piece of data

125
00:06:21,912 --> 00:06:26,268
and these servers all
work in the same way.

126
00:06:26,268 --> 00:06:27,435
So, what else?

127
00:06:28,386 --> 00:06:31,114
Well, going to a web page
will always do a get request.

128
00:06:31,114 --> 00:06:33,199
No matter where you go, the
server's always gonna see

129
00:06:33,199 --> 00:06:34,317
the same thing.

130
00:06:34,317 --> 00:06:36,898
That's because the browser,
such as Chrome or Safari

131
00:06:36,898 --> 00:06:41,485
is configured to do a get
request whenever it accesses

132
00:06:41,485 --> 00:06:43,398
a page, but there's also many other things

133
00:06:43,398 --> 00:06:47,017
that we can do such as,
host instead of get.

134
00:06:47,017 --> 00:06:50,083
We can do delete, we can
do put, options, head

135
00:06:50,083 --> 00:06:53,202
and there's many more actually.

136
00:06:53,202 --> 00:06:54,902
And once again, this
is just a piece of data

137
00:06:54,902 --> 00:06:57,526
that we're sending the
server and the server

138
00:06:57,526 --> 00:06:59,687
then can respond differently to each,

139
00:06:59,687 --> 00:07:03,353
but they normally have the same meaning

140
00:07:03,353 --> 00:07:05,136
for each server.

141
00:07:05,136 --> 00:07:07,317
So, all servers will
respond to a post request

142
00:07:07,317 --> 00:07:08,653
in similar ways.

143
00:07:08,653 --> 00:07:10,440
All servers will respond
with delete requests

144
00:07:10,440 --> 00:07:12,334
in similar ways.

145
00:07:12,334 --> 00:07:14,418
In the same way that all
servers respond to a get request

146
00:07:14,418 --> 00:07:16,146
in a similar way.

147
00:07:16,146 --> 00:07:19,056
That's because these
things are so widely used

148
00:07:19,056 --> 00:07:22,640
that they have nearly
become a standard now.

149
00:07:22,640 --> 00:07:25,909
So, the crux of this
lesson is the HTTP Verbs.

150
00:07:25,909 --> 00:07:29,817
So, here's what they normally
mean, which doesn't mean

151
00:07:29,817 --> 00:07:31,742
that they will always mean
this, but it does mean

152
00:07:31,742 --> 00:07:34,916
that this is a fairly common meaning.

153
00:07:34,916 --> 00:07:39,271
So, for the get normally
means to retrieve something.

154
00:07:39,271 --> 00:07:40,749
For example, when you go
to the Google home page

155
00:07:40,749 --> 00:07:43,913
you're retrieving the Google home page.

156
00:07:43,913 --> 00:07:46,406
In the case of an API
you may do something like

157
00:07:46,406 --> 00:07:50,041
get/item/1 and that presumably retrieves

158
00:07:50,041 --> 00:07:52,041
an item identified by 1.

159
00:07:54,138 --> 00:07:58,348
So, one may be the item's
ID or something like that.

160
00:07:58,348 --> 00:08:00,649
You nay do a post, which
for the server means

161
00:08:00,649 --> 00:08:03,928
receive data and use it,
doesn't really tell you how

162
00:08:03,928 --> 00:08:08,617
it's gonna use it, but
presumably if you do post/item

163
00:08:08,617 --> 00:08:11,200
that may create a new item see.

164
00:08:12,289 --> 00:08:14,384
Also, when you do a post request normally

165
00:08:14,384 --> 00:08:17,722
you have to send some data
along the post request.

166
00:08:17,722 --> 00:08:19,973
We're gonna look at how to do that

167
00:08:19,973 --> 00:08:24,187
and basically in this case
may be a piece of Jason

168
00:08:24,187 --> 00:08:26,395
which is name and prize
and then presumably

169
00:08:26,395 --> 00:08:29,693
the server would create an item called

170
00:08:29,693 --> 00:08:32,565
chair with price 9.99, presumably

171
00:08:32,565 --> 00:08:36,965
and we don't know unless
we look at the code.

172
00:08:36,965 --> 00:08:40,808
A put request means, make
sure that something is there.

173
00:08:40,808 --> 00:08:43,155
Notice how it doesn't say create things

174
00:08:43,155 --> 00:08:46,208
or do anything, it just makes
sure that something is there.

175
00:08:46,208 --> 00:08:50,766
So if you do put/item
with some data again,

176
00:08:50,766 --> 00:08:54,316
that may create a new chain to make sure

177
00:08:54,316 --> 00:08:56,645
that the chair exists.

178
00:08:56,645 --> 00:08:58,979
Or, if the chair's already
there, it may update

179
00:08:58,979 --> 00:09:01,137
the chair, change the price.

180
00:09:01,137 --> 00:09:04,659
Again, to make sure
whether that item is there,

181
00:09:04,659 --> 00:09:08,181
but unless the put request
allows for duplication

182
00:09:08,181 --> 00:09:09,800
then that's what it'll do.

183
00:09:09,800 --> 00:09:13,629
First it'll create it
and then will update it.

184
00:09:13,629 --> 00:09:16,347
And finally, we can also
do delete, which tends

185
00:09:16,347 --> 00:09:20,634
to mean remove something
such as delete/item/1

186
00:09:20,634 --> 00:09:22,688
and presumably that would delete the item

187
00:09:22,688 --> 00:09:24,271
with ID number one.

188
00:09:25,214 --> 00:09:27,241
Now, we've looked at four
of the most important

189
00:09:27,241 --> 00:09:30,317
HTTP Verbs, but there
are many others and we

190
00:09:30,317 --> 00:09:32,582
won't be looking at those in this course,

191
00:09:32,582 --> 00:09:34,202
but nevertheless, it's worth knowing

192
00:09:34,202 --> 00:09:36,598
that there are other types of HTTP Verbs

193
00:09:36,598 --> 00:09:37,931
that we can use.

194
00:09:38,922 --> 00:09:39,856
So, that's everything for this video.

195
00:09:39,856 --> 00:09:42,805
I wanted to introduce you
to the concept of the way

196
00:09:42,805 --> 00:09:45,587
the web works and how
these HTTP Verbs behave

197
00:09:45,587 --> 00:09:47,702
because in the next video we're gonna look

198
00:09:47,702 --> 00:09:51,675
at HTTP, sorry, at rest
APIs and these verbs

199
00:09:51,675 --> 00:09:54,280
are gonna come in really handy there.

200
00:09:54,280 --> 00:09:55,652
So, without further adieu, I'll see you

201
00:09:55,652 --> 00:09:57,569
in the very next video.

