1
00:00:00,420 --> 00:00:01,310
Welcome back.

2
00:00:01,650 --> 00:00:06,840
In this video I want to talk a little bit more about HTP requests and how they work and what they look

3
00:00:06,840 --> 00:00:07,140
like

4
00:00:11,370 --> 00:00:12,180
sort of.

5
00:00:12,600 --> 00:00:17,850
So remember when I go to a u r l and my browser like this one here it doesn't matter what it is.

6
00:00:17,910 --> 00:00:23,220
And I hit enter the most important thing that happens there's a few steps but the most important step

7
00:00:23,460 --> 00:00:31,590
is that HTP request is sent to a particular server's IP address and then the server figures out what

8
00:00:31,590 --> 00:00:36,230
to send me and then it sends a HTP response back to me.

9
00:00:36,240 --> 00:00:41,580
So if there's one thing you take away from all of this stuff about how the Internet works and HTP it's

10
00:00:41,580 --> 00:00:47,760
the request response cycle you asked for a web page and you get one back to help us learn a little bit

11
00:00:47,760 --> 00:00:48,810
more about requests.

12
00:00:48,840 --> 00:00:51,120
We're going to use a tool called postman.

13
00:00:51,240 --> 00:00:57,510
It's a free tool and the Web site is get postman dot com and all we need to do is click on get it now

14
00:00:58,770 --> 00:01:04,140
and then it will take us to a Chrome extension page and then all you need to do is click this button

15
00:01:04,260 --> 00:01:05,300
to install it.

16
00:01:05,550 --> 00:01:08,590
And then once you have it installed you can launch the app.

17
00:01:09,780 --> 00:01:11,200
So this is postman here.

18
00:01:11,380 --> 00:01:13,810
I'll go ahead and make it full screen.

19
00:01:13,890 --> 00:01:19,800
The whole point of Postman is that it lets us make HTP requests and viewer responses and it's really

20
00:01:19,800 --> 00:01:25,170
for developers to understand how things are working possibly to debug something.

21
00:01:25,170 --> 00:01:28,770
If the data is not coming back the exact way that you're expecting it to.

22
00:01:29,010 --> 00:01:33,920
We're going to use that really as an educational tool and also use it for some debugging later on.

23
00:01:34,230 --> 00:01:37,130
Once we start building some more complicated apps.

24
00:01:37,250 --> 00:01:43,050
So before I actually demonstrated just want to remind you when I go to a web page and I click enter

25
00:01:43,140 --> 00:01:50,070
I can doing here that it's making an HTP request but that's not the only way to make a request with

26
00:01:50,070 --> 00:01:50,750
postman.

27
00:01:50,760 --> 00:01:54,890
We don't actually have a web page and I can still make HTP requests.

28
00:01:54,960 --> 00:01:58,630
I just want to reiterate that we can make requests from all different places.

29
00:01:58,740 --> 00:02:01,160
We can make them from a browser like Chrome.

30
00:02:01,200 --> 00:02:03,380
We can make them from an app like Postman.

31
00:02:03,480 --> 00:02:06,150
We can make them from our command line from the terminal.

32
00:02:06,210 --> 00:02:08,430
We can make them from other apps.

33
00:02:08,730 --> 00:02:11,550
We can make them from the backend or from an iOS app.

34
00:02:11,700 --> 00:02:17,710
So the idea of HTP requests are independent of browsers.

35
00:02:17,730 --> 00:02:20,220
Let's go ahead and make our first request.

36
00:02:20,220 --> 00:02:26,700
So when we make a request the most important part is the URL that we're making the request to which

37
00:02:26,700 --> 00:02:30,030
is Google dot com in this case we're just trying to replicate.

38
00:02:30,090 --> 00:02:36,750
When I go to Google dot com in my browser and I hit enter and then there's this choice here get post

39
00:02:36,870 --> 00:02:41,310
patch put delete all these different what we call each TTP.

40
00:02:41,580 --> 00:02:45,090
And these refer to different types of requests that we can make.

41
00:02:45,240 --> 00:02:51,240
We'll be seeing these a lot more and spending more time in particular with get Post put patch and delete

42
00:02:51,240 --> 00:02:51,710
.

43
00:02:51,770 --> 00:02:54,970
These are the ones are much much less important.

44
00:02:55,020 --> 00:02:58,040
I'll give you a very quick version of what they do.

45
00:02:58,080 --> 00:03:01,800
These just tell the server what we're doing with the request.

46
00:03:01,800 --> 00:03:07,680
What type of requests we're making if we're just retrieving information like retrieving the Google home

47
00:03:07,680 --> 00:03:08,440
page.

48
00:03:08,640 --> 00:03:10,200
That's a get request.

49
00:03:10,980 --> 00:03:17,660
If I am signing up for a web site or creating a new comment on Facebook or submitting a new reddit post

50
00:03:17,660 --> 00:03:23,700
or uploading those could be post requests where I'm posting new information to a database somewhere

51
00:03:23,700 --> 00:03:28,020
I'm sending some data along with my request versus a get request.

52
00:03:28,020 --> 00:03:30,720
Typically we're not sending much data along.

53
00:03:30,720 --> 00:03:37,050
We're asking for data to come back and then put in patch are used to update things or to edit them.

54
00:03:37,080 --> 00:03:42,720
So if I wanted to update the title of a Facebook image that I had uploaded after I had already posted

55
00:03:42,720 --> 00:03:45,370
it I could use a put a patch request.

56
00:03:45,480 --> 00:03:48,140
And of course the user doesn't decide on this ever.

57
00:03:48,150 --> 00:03:54,090
This is what the developer decides on and then we have a delete request which does what it sounds like

58
00:03:54,510 --> 00:03:59,000
when a server gets a delete request it expects that you're going to delete something.

59
00:03:59,430 --> 00:04:02,570
But what's most important is that this is all just a protocol.

60
00:04:02,640 --> 00:04:09,720
Remember that HTP stands for hypertext transfer protocol so it doesn't mean that just by sending a delete

61
00:04:09,720 --> 00:04:12,460
request something is automatically deleted.

62
00:04:12,510 --> 00:04:14,850
What it does mean is that it's a protocol.

63
00:04:14,850 --> 00:04:20,550
So if I say that this is a delete request we should expect that it will delete something.

64
00:04:21,120 --> 00:04:25,410
So again very high level overview will be going into depth with all of these here.

65
00:04:25,440 --> 00:04:28,740
These first five verbs and the different types of requests.

66
00:04:28,740 --> 00:04:30,950
When we actually make a server that handles them.

67
00:04:31,230 --> 00:04:37,170
But to start I'm just going to make a get request to Google dot com and that's all we need to do.

68
00:04:37,260 --> 00:04:42,310
And if I clicked send I get a few things back.

69
00:04:42,360 --> 00:04:48,260
There are three important parts of every response the first one is the body of the response.

70
00:04:48,360 --> 00:04:49,410
That's like the payload.

71
00:04:49,410 --> 00:04:51,500
That's what is being sent back.

72
00:04:51,600 --> 00:04:55,010
So the HD mal the C Ss and the javascript in this case.

73
00:04:55,560 --> 00:04:59,690
And this is the H.M.S. s and Javascript of the Google homepage.

74
00:04:59,700 --> 00:05:08,050
This is what we would see if we went to Google and did view page source just like this there we go.

75
00:05:08,340 --> 00:05:12,130
So our browser just takes that and makes it look nice.

76
00:05:12,210 --> 00:05:15,450
Then the other thing that we get back is the headers.

77
00:05:15,720 --> 00:05:21,600
So the headers are like the meta data about the response so they contain a few pieces of information

78
00:05:21,600 --> 00:05:21,810
.

79
00:05:21,930 --> 00:05:25,460
The important ones that I'll point out are the content type.

80
00:05:25,500 --> 00:05:31,800
So this says OK just to warn you I'm sitting back HMO because we can actually send back other types

81
00:05:31,800 --> 00:05:33,110
which we'll see later on.

82
00:05:33,190 --> 00:05:35,750
All that we've seen so far though is HMO.

83
00:05:35,810 --> 00:05:40,410
Also the date and the time when this response happened when it was sent back.

84
00:05:40,410 --> 00:05:44,580
And then this thing called status which we also get up here.

85
00:05:44,580 --> 00:05:48,870
So the status code is a third big piece of information and it's just a number.

86
00:05:48,890 --> 00:05:50,480
You've probably seen them before.

87
00:05:50,490 --> 00:05:55,430
Most importantly 404 if you've ever seen before or for ever a status code.

88
00:05:55,440 --> 00:05:58,170
It's just part of the protocol of HTP.

89
00:05:58,380 --> 00:06:04,250
It's a standardized way of saying that the request that you made is good I'm going to send back status

90
00:06:04,250 --> 00:06:07,010
code 200 because I found the page you're looking for.

91
00:06:07,010 --> 00:06:08,050
Who'd you go.

92
00:06:08,120 --> 00:06:13,430
But then if we sent a request to a page that doesn't exist the server need to wait to respond back to

93
00:06:13,440 --> 00:06:13,910
us.

94
00:06:14,040 --> 00:06:17,690
So there are different status codes and they each mean different things.

95
00:06:17,690 --> 00:06:20,340
We'll be working with them again later on in the class.

96
00:06:20,390 --> 00:06:26,360
So we have the body which is the content that's being sent back the headers which contain meta data

97
00:06:26,370 --> 00:06:27,710
about the response.

98
00:06:27,870 --> 00:06:33,870
And one of those pieces is the status code and that's just a number that represents the status of this

99
00:06:33,870 --> 00:06:36,270
whole request slash response cycle.

100
00:06:36,690 --> 00:06:42,030
So demonstrate this with another Web site like Reddit dot com just like that and we'll also make you

101
00:06:42,030 --> 00:06:47,920
get request every time I load up my browser and I go to a you or I'll like Reddit dot com.

102
00:06:48,090 --> 00:06:49,350
That is a get request.

103
00:06:49,350 --> 00:06:53,750
I cannot make a post request from my browser search bar.

104
00:06:53,910 --> 00:07:00,240
We can make a post request using a h l form which we mentioned briefly when we talked about forms and

105
00:07:00,240 --> 00:07:01,410
we will be doing that.

106
00:07:01,470 --> 00:07:04,370
For now we're just focusing on get requests.

107
00:07:04,380 --> 00:07:10,670
Earlier I mentioned when we send a request like a get request we're usually asking for information back

108
00:07:11,190 --> 00:07:16,050
and when we send a post request we're trying to add date data to a database.

109
00:07:16,110 --> 00:07:21,330
So there's some sort of payload in the request where I'm sending in the information they want to be

110
00:07:21,330 --> 00:07:22,010
added.

111
00:07:22,110 --> 00:07:26,250
For instance the information to make and you post on Facebook or on Reddit.

112
00:07:26,750 --> 00:07:30,530
But we still can send some data with a get request.

113
00:07:30,570 --> 00:07:31,970
I'll give you a quick example.

114
00:07:32,070 --> 00:07:36,400
If I go to Reddit outcome which I have opened here and I do a search.

115
00:07:36,810 --> 00:07:41,780
So let's say I want to search for Corgies and I hit enter.

116
00:07:41,800 --> 00:07:43,470
Notice what happens up here.

117
00:07:43,950 --> 00:07:48,130
So it's Reddit dot com slash search question mark.

118
00:07:48,180 --> 00:07:50,010
Q equals Corgies.

119
00:07:50,120 --> 00:07:53,710
What type of requests do you think I make when I hit enter right here.

120
00:07:54,570 --> 00:08:00,270
Well I just told you a few minutes ago that the only type of request we can make is a get request from

121
00:08:00,260 --> 00:08:02,390
the browser's search bar or the nav bar.

122
00:08:02,390 --> 00:08:08,150
So this is a get request but we're also sending a little piece of information along with it which is

123
00:08:08,150 --> 00:08:10,820
our search term and it's still a get request.

124
00:08:10,830 --> 00:08:13,260
We're not adding Corgies to a database anywhere.

125
00:08:13,290 --> 00:08:16,620
We're not posting anything new to this application or to the database.

126
00:08:16,830 --> 00:08:22,140
We're purely retrieving information retrieving posts that have Corgies in their title.

127
00:08:22,130 --> 00:08:25,460
This is how we can send some data along with a get request.

128
00:08:25,620 --> 00:08:27,200
It's called the query string.

129
00:08:27,420 --> 00:08:35,190
So I can add in parameters here as many as I want something like name equals cold and it won't do anything

130
00:08:36,840 --> 00:08:42,230
but the server will get that and if it was expecting a name if read it was expecting a name parameter

131
00:08:42,620 --> 00:08:44,740
it would see that name is equal to Colt.

132
00:08:44,790 --> 00:08:47,310
So I can tag as many of these as I want.

133
00:08:47,420 --> 00:08:49,600
I can do another one here.

134
00:08:49,640 --> 00:08:58,380
City equals Assef and I can keep changing these together but they don't mean anything except for q which

135
00:08:58,380 --> 00:09:02,610
is something that the Reddit server is expecting on the search page.

136
00:09:02,700 --> 00:09:04,650
Reddit dot com slash search.

137
00:09:04,760 --> 00:09:09,660
When we make a request it's expecting queue to be equal to the search term.

138
00:09:09,650 --> 00:09:14,840
One last thing about the query string is that it always starts after a question mark and that we separate

139
00:09:15,000 --> 00:09:19,150
the key value pairs so q equals a corgi name equals cold.

140
00:09:19,160 --> 00:09:22,610
They're separated by an ampersand to actually send one of these.

141
00:09:22,810 --> 00:09:31,070
You can go back here and I can click on programs here and what harams let me do is I can add in your

142
00:09:31,190 --> 00:09:33,320
parameter key and value.

143
00:09:33,500 --> 00:09:41,840
So here let's say that I want Q To be equal to cats you can see postman makes this little request for

144
00:09:41,850 --> 00:09:44,060
me and adds the query string in.

145
00:09:44,100 --> 00:09:50,130
So now if I hit send here making a get request to read it dot com Q equals cats.

146
00:09:50,150 --> 00:09:57,330
I'm not going to get back the search results because this is on Reddit dot com slash search not just

147
00:09:57,330 --> 00:09:58,980
read it dot com.

148
00:09:59,010 --> 00:10:04,850
So now if I go back and do Reddit dot com slash search Q equals cats.

149
00:10:05,070 --> 00:10:10,390
This is making a request to the search page and saying we're searching for cats.

150
00:10:10,560 --> 00:10:14,630
Let's quick send and go to body here.

151
00:10:15,060 --> 00:10:21,810
We get a bunch of age Chimo and I'll scroll through and it's hard to see because there's so much information

152
00:10:22,190 --> 00:10:28,410
but we have references to cats in the hd a male and a postman we can actually click on preview and we

153
00:10:28,400 --> 00:10:31,700
can see that we get information about cats.

154
00:10:31,760 --> 00:10:34,090
So these are all posts about cats.

155
00:10:34,110 --> 00:10:34,920
It's not perfect.

156
00:10:34,910 --> 00:10:39,440
The C Ss isn't showing up but it's at least the HCM mouth that we can view.

157
00:10:39,540 --> 00:10:42,140
To summarize all of this we kind of covered a lot here.

158
00:10:42,140 --> 00:10:46,320
First thing was that you can make a request from all sorts of different places.

159
00:10:46,320 --> 00:10:48,710
It's not only in your browser.

160
00:10:48,720 --> 00:10:56,340
Next thing is that every request has a verb or a type and we've been making get requests only so far

161
00:10:56,750 --> 00:11:02,450
but soon we'll see post requests when we actually have a database going and we want to let users sign

162
00:11:02,460 --> 00:11:05,200
up or submit a new comment or something like that.

163
00:11:05,310 --> 00:11:10,940
They'll be sending a post request and our server is going to expect to post request and do something

164
00:11:11,040 --> 00:11:12,620
when it gets supposed request.

165
00:11:13,230 --> 00:11:20,100
So get requests are for retrieving information searching often just getting a home page or getting any

166
00:11:20,100 --> 00:11:25,730
page that doesn't involve sending data but we can still send data with the Get request.

167
00:11:25,760 --> 00:11:30,650
Usually it's when we're sending like a search query or another parameter about how we want the data

168
00:11:30,650 --> 00:11:33,230
to be sorted or what order it should be in.

169
00:11:33,440 --> 00:11:36,770
But the key is that we're still not adding anything to the database.

170
00:11:36,780 --> 00:11:39,380
This doesn't change read it's database.

171
00:11:39,650 --> 00:11:45,870
It's just asking for things that have cats in the title and all that logic happens on Reddit it's and

172
00:11:46,080 --> 00:11:51,860
written in Python and Reddit spec and is going to see that we ask for Redditt dot com slash search as

173
00:11:51,870 --> 00:11:57,210
a get request and then it has some code that will run when they get requests is made to read it dot

174
00:11:57,210 --> 00:12:04,680
com slash search and in that code it will then look for the variable queue instead of the query string

175
00:12:04,670 --> 00:12:05,120
.

176
00:12:05,140 --> 00:12:11,180
Will take the corresponding value cats retrieve all the posts all the comments or whatever it does that

177
00:12:11,180 --> 00:12:13,890
match cats and then send me back.

178
00:12:13,880 --> 00:12:21,120
All this HD mail will be returning to postman later on in this course as a way of debugging some of

179
00:12:21,120 --> 00:12:22,950
our own applications.

180
00:12:22,940 --> 00:12:24,810
Next up we're going to start talking about node
