Hey, did everyone.
They sure.
And one more type of get request, which we haven't covered yet, which is the query.
It is very important for you to understand that how data comes up with the query.
Now, query is one of the most common thing that you'll be doing, especially in the cases of search
page.
In most of the cases, what you are going to notice that somebody types something into the search bar,
or even if you do that in the Google, it comes up like for example, onto a shopping website, you
say that I want to have a t shirt that says I write code.
So in the search book you just type, I write code and in the back end I have to look through that,
how I'm going to handle that.
But the most important part is that data comes up in the query itself.
For example, there can be a shopping website again, t shirts, and you want to see there's t shirts
which are between the range of ₹300 to ₹800.
These all things are being handled into the query itself.
It is very important for you to understand this query, how it comes up and to take that data, how
we process that data.
That's a different strategy altogether.
But right now let's learn that how we can take those data in the in the variable or something.
So we're going to go ahead and make a copy of this here.
Again, looks nice.
This is, again, a great request, not the first one, because everything is coming from the URL.
And let's call this one as simply this one is going to be coarse query.
Feel free to name it, whatever.
That's just the endpoint that you have to hit.
Now let me go ahead and remove all of this, because we wouldn't be needing this.
We would be getting with that.
Okay.
Now, how are we going to handle this one?
Now, first and foremost, you need to understand that what is the name of the query that you are passing
up whenever you design forms in the HTML?
Remember, everybody says that you make sure that every for every form has some kind of a name associated
with that.
Like name, name, name, username, name, email, name, password.
So that exact name actually is responsible for being a key and value of that.
You'll understand that in a minute, but right now, let's just go with the flow.
So we will be taking two parameters or two parameters in the query itself.
One is going to be location, another one is going to be a device itself.
So let's go ahead and say let location.
So how the location comes up, just like we have requested body.
Similarly, we have requests or params.
Similarly we have got request query here.
I am pretty sure you have read a little bit of the documentation of express by now.
So now we have the location access.
Let's go ahead and access the mobile as well.
Or would be rather it would be accurate to call it as device.
Let's go ahead and have that.
So we're going to say request dot, query, dot device.
Okay.
Once we have this one, you can also go ahead and console.log the entire query itself to see what else
comes in.
But right now, I'm going to go ahead and simply say resort, send.
And in this I'm going to go ahead and pass on an object which will be this location and this device.
There we go.
So we are just taking two parameters and we are just throwing them back.
No big deal.
Let's go ahead and save this.
The important part will come up as we write the documentation for this one.
So let me go ahead and copy this one because it's a cop.
There we go.
And we'll just copy this add course because that's the nearest one and we'll modify that.
Okay.
So how this is going to add up is simply let's go ahead and paste this one, the course query.
And this is the one thing I absolutely love that when you duplicate entirety of the VTS code, any element,
it just doesn't spoil whatever is there in the clipboard of your copy status.
So that's what I love.
Okay, let's go ahead and add this also in the string.
Doesn't really matter.
This is going to be a get request.
Now summary.
This is important.
Let's go ahead and change this one.
Trying to learn about query.
Again, remember, query always goes through the URL.
Now we don't need any of the consumes and produce because we are not doing anything into the request
body.
Although if you keep produces and consume, it's no harm at all.
I'm not going to keep it.
I'll remove this one again.
This is going in the URL.
That means I have to go in the parameters again.
Let's go ahead and add a name to this one.
You don't need to.
We're going to call this one as simply location.
Feel free to change this one.
Interestingly, you have to pass on a name.
Just like previously we said that it's going into params and all of that.
This one is going to go into the query itself and that's it.
Now, is it required?
Yes.
So we are going to go ahead and pass on this required flag as true.
And now let's go ahead and type the schema.
This is going to be the most interesting part, so let's go ahead and define the schema.
Now, I don't want user to just type on anything.
I want to give user some of the selected element that only can be passed through.
So I'm going to go ahead and say that this is going to be of type string, although this is a string,
but as soon as just after the string or any data type that you go ahead, you can actually go ahead
and give him the option of enemies.
Enemies, as I mentioned, always I always give the example of airplanes.
There are three options only similar here.
I'm going to go ahead and say the options are Delhi, London, come on, London.
And of course, my favourite, which is my own city.
Okay, so this is all the options that you have got.
Now similar to this, we can go ahead and provide another of the name.
This is just one parameter we have defined.
But remember into the index file we are receiving or expecting at least one more, which is device.
So what we can do is remember this is all the first parameter.
So I'm going to go ahead and duplicate this one.
The first one is location, the second one is going to be device.
So it is also going to be passed on in the query itself.
It is also required the schema string, but the options get changed.
This time you are having device as web or the mobile.
So whatever I select, I expect that that is going to be passed on to me in the response.
The response this time is also not going to be boolean.
This is more like an object.
So let's go ahead and change that.
This is an object.
As soon as I write object, I have to write properties and the properties I'm going to go ahead and
grab an ID which is going to be of ID will be off type string.
I can actually go ahead and copy this to save us some time.
So let's go a scroll a little bit.
Yep.
Are we passing on this exact.
Not like that.
Let me go back up here.
So we are going to have the ID, but not having ID.
What we are passing on, we're passing on the location and the device.
So both of them are coming up as a string.
So let's call this one as simply name as a string and let's go ahead and make a duplicate of this one.
Name and this is going to be a value which is of type string.
Hopefully things are okay.
Not sure.
Hopefully.
Okay.
Let's go back on to the browser.
Hit a reload and there we go.
We have another get request which is the course query.
And notice here, this time we cannot write it.
Previously when we were sending the course ID, we were able to write it.
You can also restrict this with the enum that these are the only options that you can select and pass
on.
So here we are saying the course query, both of them are required.
So you are saying that this is how this is going to come in.
So value is going to be name and value.
So this is how it's going to come in.
Not really accurate.
It can be a little bit modified.
But let me show you that.
Most important thing is let's try it out and see the URL.
So let's just say my location is Jaipur and I'm looking on Mobile.
Hypothetically, of course, let's execute this.
Now notice here that this is how the URL actually goes in.
You simply name API V1 and the course query.
Then notice here it's a question mark and it says Location equals Jaipur and the device equals mobile
and we are receiving it properly.
So in the request body we are sending a location is Jaipur and the device is mobile.
So we can actually modify this a little bit.
So we're going to say that this is going to be location which is going to come up as a string and the
device which is going to come up as a string.
So I think this makes a little bit more sense.
Reload that and open this up and yep, this now makes a little bit more sense.
Okay, so go ahead, play around a little bit more.
And now you have learned that how you can handle your queries as well as how you can pass on all the
how you can handle the queries in the back end as well and how you can use them in the swagger as well.
Quite an interesting one.
Let's go ahead and catch up in the next video.