WEBVTT

00:03.790 --> 00:07.060
Hey there, everyone stay here and welcome to another video.

00:07.090 --> 00:12.220
In this video, we're going to see that how postmen can be sometimes deceiving a little bit more than

00:12.220 --> 00:12.910
deceiving.

00:12.910 --> 00:17.500
And that is the reason why we are using the eggs and we are injecting a little bit of front in here.

00:17.500 --> 00:21.880
But again, make sure you fire up your postman and after that, make sure your server is also up and

00:21.880 --> 00:22.960
running should it be a big deal?

00:22.960 --> 00:26.380
We are so far into the course just firing up the server shouldn't be a big deal.

00:26.650 --> 00:31.270
So what we're going to do is once we have created the app and once we are into the listen mode, let's

00:31.270 --> 00:34.260
go ahead and see that how we can actually handle the get request.

00:34.270 --> 00:38.770
Now, only thing that we are going to study in this particular video is this the gate request.

00:38.770 --> 00:42.700
We'll handle the post request later on, but that's going to be a little bit easier after this one.

00:42.850 --> 00:47.950
So we're going to say that I will use a get request and let's call this one as my get.

00:48.040 --> 00:50.530
Yeah, that's kind of a basic name.

00:50.620 --> 00:53.620
Let's use a slash might get, otherwise it will give us errors.

00:53.800 --> 00:58.870
So let's use a request and response and this request in response goes like this.

00:59.140 --> 01:02.500
Now I'm going to go ahead and simply log whatever the request is coming in.

01:02.500 --> 01:05.470
And in fact, I'm going to say request dot body, just like we have seen.

01:05.860 --> 01:07.570
And we can also do a response.

01:07.570 --> 01:12.280
So we're going to say raise, dart, send and whatever the request body is coming in so we can send

01:12.280 --> 01:16.330
it as it is back so that it's easier for us in the postman to handle this.

01:16.660 --> 01:16.870
Okay.

01:16.960 --> 01:19.810
We have seen this kind of situation in the past as well.

01:19.810 --> 01:23.290
Let's go ahead and analyze or kind of revise what we have seen in the past.

01:23.290 --> 01:27.970
So I'm going to go ahead and open this up again in case you want to use the variables, you are more

01:27.970 --> 01:31.000
than welcome, but in case you want to use.

01:31.000 --> 01:33.700
Come on, domain.

01:33.700 --> 01:34.420
There we go.

01:34.960 --> 01:36.040
So this is the domain.

01:36.040 --> 01:38.830
This is the variable that we already created in this course.

01:38.830 --> 01:43.780
But again, in case you are using something else, like a local host or something, that is absolutely

01:43.780 --> 01:44.350
fine.

01:44.350 --> 01:46.630
Now what I want to do is look into the body.

01:46.630 --> 01:52.000
And in case you remember, we previously went with the raw and using not the text but actually the JSON

01:52.000 --> 01:52.720
format.

01:52.720 --> 01:55.000
And let's go ahead and send some JSON data.

01:55.000 --> 01:59.130
I'm going to go ahead and just send my name just like this and I'll be saying, Hit Dash.

01:59.230 --> 01:59.890
That's it.

02:00.010 --> 02:05.440
When I go ahead and send this one, it says, hey, this is going undefined, as you can see up here

02:05.440 --> 02:05.740
as well.

02:05.740 --> 02:07.960
Let me get a little bit space.

02:09.170 --> 02:14.330
And a little bit spacing up here so that we can actually see the result just here at the very corner.

02:14.330 --> 02:15.740
I know, but we can see that.

02:15.740 --> 02:20.600
So this is giving me undefined why it is not giving me a defined because we have previously used that

02:20.600 --> 02:21.980
one in such situation.

02:21.980 --> 02:23.690
Obviously your first idea should behave.

02:23.690 --> 02:28.460
We haven't defined any kind of middleware, so let's go ahead and write a simple comment that we want

02:28.460 --> 02:29.780
to declare some middleware.

02:29.780 --> 02:34.790
The most common one we have used so far is app use, and we simply go in and say, Hey, express, some

02:34.790 --> 02:38.210
data will be coming up and that data might be in the JSON format.

02:38.210 --> 02:39.830
So go ahead and use that one.

02:39.830 --> 02:43.460
Once I go ahead and enter this middleware, I go ahead and send this data again.

02:43.460 --> 02:46.370
Now I'm able to receive the data, so that is a good thing.

02:46.520 --> 02:51.260
Now one more thing I would like to bring to your attention and something weird that express actually

02:51.260 --> 02:51.830
does that.

02:51.830 --> 02:56.690
So let me show you that this is a simple Google Home page, and whenever you make a request, this is

02:56.690 --> 02:58.070
actually a form itself.

02:58.070 --> 03:02.480
So we're going to go ahead and make a simple result, which is going to be simply my name.

03:02.480 --> 03:04.430
So let's go ahead and use that.

03:04.460 --> 03:05.990
Let's go ahead and hit enter.

03:06.320 --> 03:07.730
So this is the name.

03:07.730 --> 03:13.640
What I want you to bring your attention is notice here in the URL, let's say search question mark Q

03:13.640 --> 03:14.370
equals to hit.

03:14.570 --> 03:19.100
And in fact if you go to any shopping website or anything, whenever you fill the form which is search

03:19.130 --> 03:24.290
form or anything like that, which is not very crucial or sensitive information, they always go in

03:24.290 --> 03:27.020
the URL in this format, question mark equals two.

03:27.020 --> 03:30.920
And if you remember the documentation of express itself, this is a query.

03:30.920 --> 03:32.630
So we read this together.

03:32.630 --> 03:36.260
So let me go again back onto the Express documentation.

03:36.260 --> 03:38.420
So we're going to go ahead and say Express.

03:39.140 --> 03:39.830
JS.

03:39.830 --> 03:44.930
So let me go up here and we're going to go on to the Express GS documentation.

03:45.230 --> 03:50.960
We know that in the API reference itself we can see the request and request can actually come up from

03:50.960 --> 03:51.920
the query itself.

03:51.920 --> 03:54.380
So request, dot query and this is how we deal with that.

03:54.380 --> 03:58.850
So request either route or request or query however you want to handle that.

03:58.850 --> 04:01.160
So this is their request route.

04:01.160 --> 04:02.930
You can actually go ahead and use that.

04:02.930 --> 04:06.620
And there are a couple of other ways that can be used up here at this point.

04:06.620 --> 04:12.710
So request, dot, route, request, dot, query and notice here they are using some of the nicer documentation

04:12.800 --> 04:13.670
here as well.

04:13.670 --> 04:17.540
But what I want to why I'm showing you all of this, because it is very common.

04:17.540 --> 04:22.640
I have seen some times that people want to actually go ahead and say request, dot, query and in fact,

04:22.640 --> 04:25.100
they also want to dump this one out here.

04:25.100 --> 04:27.800
Now, let's see what all happens in this case.

04:27.800 --> 04:28.730
This is very important.

04:28.730 --> 04:32.450
This is not going to work, obviously, but it is important for you to understand this part.

04:32.570 --> 04:36.560
If I go ahead and send this one, obviously, this is how you are sending the raw data.

04:36.560 --> 04:38.480
So this is not going to work either.

04:38.480 --> 04:41.840
This is going to work in the form data or the form URL encoded.

04:41.930 --> 04:43.070
Now, let me break it to you.

04:43.070 --> 04:47.510
Already, the form data is not going to work because everything that travels in this is going to travel

04:47.510 --> 04:48.320
in the URL.

04:48.320 --> 04:50.720
It needs to be converted into URL and coded.

04:50.720 --> 04:54.710
So everything replaces like your spaces getting replaced by person 20.

04:54.710 --> 04:56.330
This is a classic URL encoding.

04:56.330 --> 04:59.960
You can search more about it on the on the simple Google search.

04:59.960 --> 05:07.070
Let's go up here and we're going to go ahead and save this time name and let's call this one as my name

05:07.070 --> 05:07.610
again.

05:07.610 --> 05:09.620
But full name this time.

05:10.500 --> 05:11.030
Okay.

05:11.580 --> 05:15.900
Let's go ahead and send this one and notice we are seeing an empty parenthesis here.

05:15.930 --> 05:18.110
Why this empty parenthesis?

05:18.120 --> 05:22.650
Because the way how Express actually handles this is not in the query.

05:22.680 --> 05:25.650
Actually, all of your form comes into the body itself.

05:25.680 --> 05:26.040
Yes.

05:26.040 --> 05:26.910
Surprise, surprise.

05:26.910 --> 05:28.170
But this is how it works.

05:28.170 --> 05:34.080
So if I go ahead and change it back to the request body and try to send this form again, notice here,

05:34.080 --> 05:35.190
this is still saying empty.

05:35.190 --> 05:39.630
And I'll tell you the reason why this is all happening, but this is how it is usually comes in.

05:39.840 --> 05:44.340
Notice here, I told you this is going to get you URL encoded, but right now I'm expecting all the

05:44.340 --> 05:46.470
data to come up into the JSON format.

05:46.470 --> 05:51.330
So I need to use another middleware in this case so that I can handle this particular situation which

05:51.330 --> 05:56.530
is express dot URL encoded and this is how this is going to work.

05:56.550 --> 06:00.330
Now notice it is going to give me a couple of errors that hey, body parts that is deprecated.

06:00.360 --> 06:05.640
No, I don't have any body person included, but still it gives a kind of a line to me and it says,

06:05.640 --> 06:07.080
Hey, provide the extended option.

06:07.080 --> 06:11.160
I'll talk about the extended option in a minute, but let's see first how this is going to work.

06:11.370 --> 06:15.810
So I'm going to go ahead and again use the URL encoded form and I'm going to go ahead and send this

06:15.810 --> 06:16.320
one.

06:16.320 --> 06:16.630
Okay.

06:16.710 --> 06:19.080
I'm getting the name Equal Stage.

06:19.530 --> 06:20.550
So this is all working.

06:20.550 --> 06:25.920
Why this is yelling at me that you are an extended and also you might have seen a couple of like thousands

06:25.920 --> 06:29.780
of videos and all of that that automatically uses extended equals to true.

06:29.790 --> 06:32.100
Let me show you what does that means.

06:32.430 --> 06:32.670
Okay.

06:32.730 --> 06:36.480
Now, what is going to happen in this if you are going to just scroll it a little bit that this is the

06:36.480 --> 06:39.630
data you can actually send it and this is how you are coming in.

06:39.810 --> 06:41.670
Now, sometimes let me just show you up here.

06:41.670 --> 06:43.350
This is actually much more easier.

06:43.350 --> 06:45.630
So this is the data you are sending in right now.

06:45.630 --> 06:46.890
This is how it is coming up.

06:46.890 --> 06:51.000
So something like this and again, both are under the codes like that.

06:52.540 --> 06:53.170
This is.

06:53.170 --> 06:58.330
But let's just say your data is going to come up into the format, which is a little bit more complicated

06:58.330 --> 06:59.080
probably.

06:59.260 --> 07:02.240
It's going to be having full name and further down the road.

07:02.260 --> 07:04.870
This full name is also an object.

07:05.050 --> 07:12.330
This is having a property of a first name just like this and then having a property of H.

07:12.340 --> 07:15.130
And probably after that there is a last name.

07:15.850 --> 07:18.910
This is how it is going on and again to much of the code.

07:18.910 --> 07:21.340
But this is easier to understand here.

07:22.840 --> 07:25.210
So notice here one level of depth.

07:25.210 --> 07:27.970
When I say name and attach, that is absolutely fine.

07:27.970 --> 07:31.300
But this kind of a level of in depth, this is not fine.

07:31.300 --> 07:34.210
This is not accepted right now into the form itself.

07:34.210 --> 07:37.110
And yes, there are ways sometimes form actually works this way.

07:37.120 --> 07:39.640
So in case you want that, this is also allowed.

07:39.640 --> 07:42.460
I want to handle every single situation that comes in.

07:42.460 --> 07:45.670
So in that case, you actually go ahead and provide an object here.

07:45.670 --> 07:47.860
Let's go ahead and say, hey, extend it is true.

07:47.860 --> 07:50.140
So that is allowed in case something comes like that.

07:50.140 --> 07:53.680
I'll write code in a way that is allowed or I can actually manage that.

07:53.680 --> 07:57.760
So this is a little bit of vague of idea, but this is how the extended actually means.

07:57.760 --> 08:00.160
So that actually reveals the error as well.

08:00.190 --> 08:01.870
It gives you a not supporting that to.

08:01.870 --> 08:03.670
So I always love to place this one.

08:03.850 --> 08:04.110
Okay.

08:04.150 --> 08:05.050
Coming back up here.

08:05.050 --> 08:10.240
Now I'm able to send this data and I'm able to receive this data that is good and that is fine.

08:10.570 --> 08:10.820
Okay.

08:10.930 --> 08:15.820
What I do is now moving to the form data and I go ahead and say, hey, I'm sending the name and I'm

08:15.820 --> 08:19.120
sending a name of Rahul and I go ahead and send this data.

08:19.120 --> 08:20.620
What happens in that case?

08:20.710 --> 08:21.550
Nothing.

08:21.580 --> 08:22.180
Why?

08:22.180 --> 08:25.780
Because this is a classic form and form needs to be all encoded.

08:25.780 --> 08:27.700
So you won't be using this one up here.

08:27.700 --> 08:32.440
Now, although they give you the option of having the text as well as fill up here and when it goes

08:32.440 --> 08:34.840
to the you are encoded, they don't give you this option.

08:34.840 --> 08:39.850
Yes, there is a little bit dots up here and all of that, but these dots only work into the form data

08:39.850 --> 08:40.300
itself.

08:40.300 --> 08:43.060
They give you a lot of the content type up here, not like that.

08:43.060 --> 08:47.890
So you come up into the picture, a problem that, hey, I want to send the URL encoded data, but I

08:47.890 --> 08:49.480
also want to send some pictures.

08:49.480 --> 08:51.400
I want to learn how to upload images.

08:51.400 --> 08:55.600
And that's where some of the limitations of the postman comes in, that if you want to send the form

08:55.600 --> 08:57.010
data, just send the farm data.

08:57.010 --> 08:58.090
Don't send this one.

08:58.090 --> 09:03.400
And this is exactly the reason why I want to use edges so that I can tell you how farm looks like we

09:03.400 --> 09:06.190
will be at the same time let you see your registering a user.

09:06.190 --> 09:10.810
You will be sending his first name, last name, email, password, and also the photo maybe.

09:10.810 --> 09:12.310
Or yes, you are creating a product.

09:12.310 --> 09:15.070
You will be sending some product information and the photo itself.

09:15.100 --> 09:18.040
How am I going to teach you that in the post itself?

09:18.040 --> 09:19.510
So that is not possible.

09:19.540 --> 09:20.980
So let's just wrap it up.

09:20.980 --> 09:24.280
Yes, we need the middleware and this is how each middleware works.

09:24.280 --> 09:29.380
And when I go to this app Target and all these things, this is all drama that we have done up here.

09:29.410 --> 09:34.810
Now, in the next video, we are going to go ahead and set up our edges, the simple kind of templating

09:34.810 --> 09:35.230
engine.

09:35.230 --> 09:36.400
It's really super easy.

09:36.400 --> 09:38.260
Again, everything is super easy with me.

09:38.260 --> 09:40.900
So this is also going to be super easy and interesting.

09:40.900 --> 09:42.580
Let's catch up in the next video.
