Hey there, everyone stay here and welcome to another video.
In this video, we're going to see that how postmen can be sometimes deceiving a little bit more than
deceiving.
And that is the reason why we are using the eggs and we are injecting a little bit of front in here.
But again, make sure you fire up your postman and after that, make sure your server is also up and
running should it be a big deal?
We are so far into the course just firing up the server shouldn't be a big deal.
So what we're going to do is once we have created the app and once we are into the listen mode, let's
go ahead and see that how we can actually handle the get request.
Now, only thing that we are going to study in this particular video is this the gate request.
We'll handle the post request later on, but that's going to be a little bit easier after this one.
So we're going to say that I will use a get request and let's call this one as my get.
Yeah, that's kind of a basic name.
Let's use a slash might get, otherwise it will give us errors.
So let's use a request and response and this request in response goes like this.
Now I'm going to go ahead and simply log whatever the request is coming in.
And in fact, I'm going to say request dot body, just like we have seen.
And we can also do a response.
So we're going to say raise, dart, send and whatever the request body is coming in so we can send
it as it is back so that it's easier for us in the postman to handle this.
Okay.
We have seen this kind of situation in the past as well.
Let's go ahead and analyze or kind of revise what we have seen in the past.
So I'm going to go ahead and open this up again in case you want to use the variables, you are more
than welcome, but in case you want to use.
Come on, domain.
There we go.
So this is the domain.
This is the variable that we already created in this course.
But again, in case you are using something else, like a local host or something, that is absolutely
fine.
Now what I want to do is look into the body.
And in case you remember, we previously went with the raw and using not the text but actually the JSON
format.
And let's go ahead and send some JSON data.
I'm going to go ahead and just send my name just like this and I'll be saying, Hit Dash.
That's it.
When I go ahead and send this one, it says, hey, this is going undefined, as you can see up here
as well.
Let me get a little bit space.
And a little bit spacing up here so that we can actually see the result just here at the very corner.
I know, but we can see that.
So this is giving me undefined why it is not giving me a defined because we have previously used that
one in such situation.
Obviously your first idea should behave.
We haven't defined any kind of middleware, so let's go ahead and write a simple comment that we want
to declare some middleware.
The most common one we have used so far is app use, and we simply go in and say, Hey, express, some
data will be coming up and that data might be in the JSON format.
So go ahead and use that one.
Once I go ahead and enter this middleware, I go ahead and send this data again.
Now I'm able to receive the data, so that is a good thing.
Now one more thing I would like to bring to your attention and something weird that express actually
does that.
So let me show you that this is a simple Google Home page, and whenever you make a request, this is
actually a form itself.
So we're going to go ahead and make a simple result, which is going to be simply my name.
So let's go ahead and use that.
Let's go ahead and hit enter.
So this is the name.
What I want you to bring your attention is notice here in the URL, let's say search question mark Q
equals to hit.
And in fact if you go to any shopping website or anything, whenever you fill the form which is search
form or anything like that, which is not very crucial or sensitive information, they always go in
the URL in this format, question mark equals two.
And if you remember the documentation of express itself, this is a query.
So we read this together.
So let me go again back onto the Express documentation.
So we're going to go ahead and say Express.
JS.
So let me go up here and we're going to go on to the Express GS documentation.
We know that in the API reference itself we can see the request and request can actually come up from
the query itself.
So request, dot query and this is how we deal with that.
So request either route or request or query however you want to handle that.
So this is their request route.
You can actually go ahead and use that.
And there are a couple of other ways that can be used up here at this point.
So request, dot, route, request, dot, query and notice here they are using some of the nicer documentation
here as well.
But what I want to why I'm showing you all of this, because it is very common.
I have seen some times that people want to actually go ahead and say request, dot, query and in fact,
they also want to dump this one out here.
Now, let's see what all happens in this case.
This is very important.
This is not going to work, obviously, but it is important for you to understand this part.
If I go ahead and send this one, obviously, this is how you are sending the raw data.
So this is not going to work either.
This is going to work in the form data or the form URL encoded.
Now, let me break it to you.
Already, the form data is not going to work because everything that travels in this is going to travel
in the URL.
It needs to be converted into URL and coded.
So everything replaces like your spaces getting replaced by person 20.
This is a classic URL encoding.
You can search more about it on the on the simple Google search.
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
again.
But full name this time.
Okay.
Let's go ahead and send this one and notice we are seeing an empty parenthesis here.
Why this empty parenthesis?
Because the way how Express actually handles this is not in the query.
Actually, all of your form comes into the body itself.
Yes.
Surprise, surprise.
But this is how it works.
So if I go ahead and change it back to the request body and try to send this form again, notice here,
this is still saying empty.
And I'll tell you the reason why this is all happening, but this is how it is usually comes in.
Notice here, I told you this is going to get you URL encoded, but right now I'm expecting all the
data to come up into the JSON format.
So I need to use another middleware in this case so that I can handle this particular situation which
is express dot URL encoded and this is how this is going to work.
Now notice it is going to give me a couple of errors that hey, body parts that is deprecated.
No, I don't have any body person included, but still it gives a kind of a line to me and it says,
Hey, provide the extended option.
I'll talk about the extended option in a minute, but let's see first how this is going to work.
So I'm going to go ahead and again use the URL encoded form and I'm going to go ahead and send this
one.
Okay.
I'm getting the name Equal Stage.
So this is all working.
Why this is yelling at me that you are an extended and also you might have seen a couple of like thousands
of videos and all of that that automatically uses extended equals to true.
Let me show you what does that means.
Okay.
Now, what is going to happen in this if you are going to just scroll it a little bit that this is the
data you can actually send it and this is how you are coming in.
Now, sometimes let me just show you up here.
This is actually much more easier.
So this is the data you are sending in right now.
This is how it is coming up.
So something like this and again, both are under the codes like that.
This is.
But let's just say your data is going to come up into the format, which is a little bit more complicated
probably.
It's going to be having full name and further down the road.
This full name is also an object.
This is having a property of a first name just like this and then having a property of H.
And probably after that there is a last name.
This is how it is going on and again to much of the code.
But this is easier to understand here.
So notice here one level of depth.
When I say name and attach, that is absolutely fine.
But this kind of a level of in depth, this is not fine.
This is not accepted right now into the form itself.
And yes, there are ways sometimes form actually works this way.
So in case you want that, this is also allowed.
I want to handle every single situation that comes in.
So in that case, you actually go ahead and provide an object here.
Let's go ahead and say, hey, extend it is true.
So that is allowed in case something comes like that.
I'll write code in a way that is allowed or I can actually manage that.
So this is a little bit of vague of idea, but this is how the extended actually means.
So that actually reveals the error as well.
It gives you a not supporting that to.
So I always love to place this one.
Okay.
Coming back up here.
Now I'm able to send this data and I'm able to receive this data that is good and that is fine.
Okay.
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
sending a name of Rahul and I go ahead and send this data.
What happens in that case?
Nothing.
Why?
Because this is a classic form and form needs to be all encoded.
So you won't be using this one up here.
Now, although they give you the option of having the text as well as fill up here and when it goes
to the you are encoded, they don't give you this option.
Yes, there is a little bit dots up here and all of that, but these dots only work into the form data
itself.
They give you a lot of the content type up here, not like that.
So you come up into the picture, a problem that, hey, I want to send the URL encoded data, but I
also want to send some pictures.
I want to learn how to upload images.
And that's where some of the limitations of the postman comes in, that if you want to send the form
data, just send the farm data.
Don't send this one.
And this is exactly the reason why I want to use edges so that I can tell you how farm looks like we
will be at the same time let you see your registering a user.
You will be sending his first name, last name, email, password, and also the photo maybe.
Or yes, you are creating a product.
You will be sending some product information and the photo itself.
How am I going to teach you that in the post itself?
So that is not possible.
So let's just wrap it up.
Yes, we need the middleware and this is how each middleware works.
And when I go to this app Target and all these things, this is all drama that we have done up here.
Now, in the next video, we are going to go ahead and set up our edges, the simple kind of templating
engine.
It's really super easy.
Again, everything is super easy with me.
So this is also going to be super easy and interesting.
Let's catch up in the next video.