1
00:00:00,150 --> 00:00:05,400
All right, we're done with the basics, but there are two major issues with our current setup.

2
00:00:05,580 --> 00:00:10,940
First of all, we don't provide any info about the data that we're sending back.

3
00:00:11,490 --> 00:00:16,910
So we don't have any metadata about the body that we're sending out.

4
00:00:17,220 --> 00:00:22,530
So we're not providing any information, which is go restaurant and then pass in strength.

5
00:00:22,800 --> 00:00:24,180
So that's issue number one.

6
00:00:24,570 --> 00:00:33,990
And then issue number two, if I were to go to the localhost five thousand and if I type about or if

7
00:00:33,990 --> 00:00:39,930
I type contact or whatever, you see that, of course, we're sending back the same response each and

8
00:00:39,930 --> 00:00:40,390
every time.

9
00:00:40,410 --> 00:00:44,490
So if we go with contact again, this is going to be a homepage.

10
00:00:44,910 --> 00:00:53,100
So why don't we deal with issue number one first where we provide more info to the browser of what we're

11
00:00:53,100 --> 00:00:54,210
actually sending back.

12
00:00:54,960 --> 00:01:02,700
And then the next video, we'll deal with the request and the way we provide more info, we just need

13
00:01:02,700 --> 00:01:07,260
to add more methods, not specifically one more method.

14
00:01:07,260 --> 00:01:10,620
And that is going to be vorys dot right head.

15
00:01:10,980 --> 00:01:15,360
And in there, you can probably already guess that we are just providing headers.

16
00:01:16,050 --> 00:01:19,530
So we're providing metadata about our response.

17
00:01:19,830 --> 00:01:25,230
And we go here with red dot and then we go with right hand.

18
00:01:25,740 --> 00:01:29,330
So right hand and then we need to provide a few things.

19
00:01:29,640 --> 00:01:34,250
We start with a status code and I'll talk about these tax code in a second.

20
00:01:34,530 --> 00:01:40,230
And for the time being, I'll just pass in two hundred, which just means that the request was successful

21
00:01:40,500 --> 00:01:46,650
and then we pass in the headers and one of the most common headers is the content type.

22
00:01:47,190 --> 00:01:53,040
So this is where I specifically say to the browser, hey, listen, I'm sending back the email or I'm

23
00:01:53,040 --> 00:01:55,410
sending back access or I'm sending back the image.

24
00:01:55,710 --> 00:02:00,500
So Browser knows what to do, how to render that content.

25
00:02:00,780 --> 00:02:05,640
And like I mentioned already previously, this is done using key value pairs.

26
00:02:05,880 --> 00:02:07,440
So we go with content type.

27
00:02:07,620 --> 00:02:11,910
So that's the name of the header and then we pass in text.

28
00:02:12,400 --> 00:02:20,220
And if, for example, I want to pass in the HDMI, I go text forward slash and then actually email.

29
00:02:20,400 --> 00:02:26,070
And now of course in this case where I have the restaurant, I can set up the demo.

30
00:02:26,290 --> 00:02:28,560
So for example, I could go with adding one.

31
00:02:29,730 --> 00:02:37,770
And I will say homepage, same deal homepage now, if you want, you can keep it this way where you

32
00:02:37,770 --> 00:02:42,370
have Verizon orendain, you directly pass in the mail.

33
00:02:42,550 --> 00:02:46,320
However, I like to use better this approach where I go with.

34
00:02:46,530 --> 00:02:48,030
Whereas that's right.

35
00:02:48,240 --> 00:02:49,560
And we do the same thing.

36
00:02:49,560 --> 00:02:51,510
We pass in essentially the body.

37
00:02:51,720 --> 00:02:58,920
And I set up my HMO here in the right or any content that I'm sending back and then explicitly call

38
00:02:58,920 --> 00:03:00,240
a restaurant again.

39
00:03:00,630 --> 00:03:04,880
If you want, you can pass this one into the end.

40
00:03:04,890 --> 00:03:06,660
Just make sure that you have the end.

41
00:03:06,900 --> 00:03:12,980
And you saw that in the docs where it's as if they're specified in a similar effect to calling respons

42
00:03:12,990 --> 00:03:13,110
out.

43
00:03:13,110 --> 00:03:13,500
Right.

44
00:03:13,650 --> 00:03:17,910
And then we pass in the data followed by restaurant.

45
00:03:17,910 --> 00:03:19,860
But you always, always need to call.

46
00:03:20,070 --> 00:03:20,950
Whereas Noren.

47
00:03:20,970 --> 00:03:22,110
So this is a really up to you.

48
00:03:22,350 --> 00:03:25,170
You want you can pass this directly into restaurant.

49
00:03:25,530 --> 00:03:29,820
I like to write it a bit supposedly where I say, is that right?

50
00:03:29,850 --> 00:03:31,170
So that is my body.

51
00:03:31,380 --> 00:03:39,120
And then I just and the communication, my calling or as a dot then and now, of course, if I go back

52
00:03:39,120 --> 00:03:46,620
to the browser again, I'll still have the same issue where it's going to be displayed for every request,

53
00:03:46,620 --> 00:03:49,620
meaning either contact page, home page or whatever.

54
00:03:50,040 --> 00:03:53,760
But now I provide way more useful info to the browser.

55
00:03:53,970 --> 00:04:01,700
Web browser knows, hey, I'm getting back the HMO so I'll need to run our HMO and this stuff matters.

56
00:04:01,840 --> 00:04:10,340
So let me show you, if I change the content type back, for example, to plain and if I shave and if

57
00:04:10,350 --> 00:04:11,940
you refresh, no notice.

58
00:04:12,210 --> 00:04:15,080
This is now treated as a tax.

59
00:04:15,480 --> 00:04:17,399
It's not treated as HMO.

60
00:04:17,610 --> 00:04:22,350
So whatever you set up or here in the content type, yes, it does matter.

61
00:04:22,350 --> 00:04:25,740
Now, Xpress takes care of that, so we won't have to do that.

62
00:04:25,740 --> 00:04:29,510
But I just want to let you know that if you will be setting up these errors yourself.

63
00:04:29,760 --> 00:04:30,150
Yes.

64
00:04:30,150 --> 00:04:32,160
The stuff that you type here matters.

65
00:04:32,280 --> 00:04:38,070
And it is also called MYM type, or you can think of it as media type.

66
00:04:38,070 --> 00:04:46,830
So whatever we're sending back and now let's go over the status codes as well as other options for modern

67
00:04:46,860 --> 00:04:47,160
times.

68
00:04:47,550 --> 00:04:53,820
And this is where I would like to introduce an awesome resource for anything I should be related.

69
00:04:54,030 --> 00:04:56,970
And that is going to be no other than the Mozilla docs.

70
00:04:57,180 --> 00:05:04,920
So if you go to HTP and status codes, you'll see probably the first link is going to be to the MTM.

71
00:05:05,160 --> 00:05:13,020
And as you can see, HTP response that codes indicate whether specific HTP request has been successfully

72
00:05:13,170 --> 00:05:13,740
completed.

73
00:05:13,980 --> 00:05:19,560
And like I mentioned before, there are quite a few groups over here and there are quite a few codes.

74
00:05:19,860 --> 00:05:25,650
But I would strongly discourage you from spending your weekend on memorizing the codes as we're going

75
00:05:25,650 --> 00:05:30,150
to be progressing with the course, as we're going to be creating more complex applications.

76
00:05:30,150 --> 00:05:33,420
Of course, we'll introduce more and more status codes.

77
00:05:33,750 --> 00:05:41,310
But the main idea is following where when we send back the response, I'm just saying, is it successful?

78
00:05:41,670 --> 00:05:44,460
Maybe the resource wasn't available.

79
00:05:44,610 --> 00:05:49,140
So then I sent back four or four or maybe there was a bad request.

80
00:05:49,260 --> 00:05:51,570
That's why there's also option four hundred.

81
00:05:51,810 --> 00:05:58,500
And hopefully you get an idea where we are setting up that status code so the browser knows what is

82
00:05:58,500 --> 00:06:00,870
happening with the request.

83
00:06:01,110 --> 00:06:02,340
Was it successful?

84
00:06:02,610 --> 00:06:03,810
Was there an error?

85
00:06:03,840 --> 00:06:04,320
Maybe.

86
00:06:04,320 --> 00:06:04,830
I don't know.

87
00:06:04,980 --> 00:06:06,750
You're not authorized to access it.

88
00:06:06,960 --> 00:06:08,610
And on and on and on.

89
00:06:08,910 --> 00:06:17,070
And if you keep on scrolling notice, so the ones are going to be informational responses then for successful

90
00:06:17,070 --> 00:06:18,780
one, we have two on red.

91
00:06:19,200 --> 00:06:22,170
So that probably is going to be the one that you'll use the most.

92
00:06:22,440 --> 00:06:25,260
So that means that request has succeeded.

93
00:06:25,560 --> 00:06:30,090
Then we have to add one also something that we'll use throughout the course a lot.

94
00:06:30,270 --> 00:06:34,440
And this one is once the post request is successful.

95
00:06:34,680 --> 00:06:39,630
So if you are the resource successfully onto the server, then you sent back to one.

96
00:06:40,380 --> 00:06:43,050
We have three hundreds for redirect.

97
00:06:43,380 --> 00:06:48,900
And then these are the ones that you probably don't want to get if you are surfing the web.

98
00:06:49,140 --> 00:06:51,540
So four hundred is for by request.

99
00:06:51,960 --> 00:06:57,270
So for example, you are requesting some kind of data or you're trying to do something on the server,

100
00:06:57,570 --> 00:06:59,670
but you don't provide the info.

101
00:07:00,150 --> 00:07:01,140
So I don't know.

102
00:07:01,140 --> 00:07:06,390
I'm trying to add the user, but I don't provide the user name something along those lines.

103
00:07:06,660 --> 00:07:12,450
One for one is for unauthorized than four or three for Ben and for or for not phone.

104
00:07:12,780 --> 00:07:20,070
So in our case, we'll set up a response if the user is trying to access the resource that does not

105
00:07:20,070 --> 00:07:20,850
exist.

106
00:07:21,240 --> 00:07:24,870
So hopefully it is clear that is the status code.

107
00:07:25,050 --> 00:07:29,040
Again, I wouldn't suggest memorizing it as we are.

108
00:07:29,240 --> 00:07:34,490
Moving along with the course, of course, will cover more status codes, just understand the main idea

109
00:07:34,940 --> 00:07:40,150
where you attach the status code to let the browser know, hey, what's happening?

110
00:07:40,460 --> 00:07:46,560
And it is very important that you use the correct sars-cov-2 because we are in charge here.

111
00:07:46,730 --> 00:07:53,240
Nothing stops me from sending back the 404 here, meaning the resource is not found.

112
00:07:54,250 --> 00:08:01,780
And then when you navigate to the contact page, for example, here, and if you inspect, again, the

113
00:08:01,780 --> 00:08:08,520
browser network tab, you'll see this confusing info for four or four years, technically an iPhone.

114
00:08:09,160 --> 00:08:09,540
Right.

115
00:08:09,880 --> 00:08:14,060
But at the same time, we are sending back the correct results.

116
00:08:14,200 --> 00:08:18,020
So, yes, whatever we typed as far as that is code, it does matter.

117
00:08:18,340 --> 00:08:25,130
It's not just some random info that just reflects what is happening with the request.

118
00:08:25,600 --> 00:08:27,660
And then lastly, let's talk about types.

119
00:08:27,680 --> 00:08:28,380
Same deal.

120
00:08:28,570 --> 00:08:34,330
Just go to your favorite search engine and just type my name and types.

121
00:08:34,480 --> 00:08:39,610
And again, I suggest using the M, the N, and these are just going to be media types.

122
00:08:39,820 --> 00:08:43,760
So whatever we sending back, there's quite a few out there.

123
00:08:44,049 --> 00:08:49,210
Now, again, Express takes care of that, so we don't need to worry about it.

124
00:08:49,510 --> 00:08:53,400
But if you ever need to set it up, I don't suggest memorizing them.

125
00:08:54,180 --> 00:08:58,750
The ones that you'll need to use, you'll pretty much be able to Google it right away.

126
00:08:58,960 --> 00:09:05,440
You can also use the NPM packages, so now you don't need to go and memorize them again.

127
00:09:05,650 --> 00:09:11,070
Just remember the main idea where you're sending back something, right?

128
00:09:11,380 --> 00:09:15,500
I want you to describe to the browser, well, what are you sending back?

129
00:09:16,060 --> 00:09:18,510
Are you sending back the image or are you sending back others?

130
00:09:18,730 --> 00:09:20,560
Are you sending back the e-mail?

131
00:09:20,770 --> 00:09:27,580
And as you saw in the previous example, if you change that mind type, if you change that content type

132
00:09:27,580 --> 00:09:31,950
header, yes, the browser will interpret that differently.

133
00:09:32,290 --> 00:09:36,350
And once we successfully have set up more proper response.

134
00:09:36,370 --> 00:09:39,850
Now, let's start dealing with the request object.

