WEBVTT

00:03.780 --> 00:04.630
Hey, did everyone.

00:04.720 --> 00:05.290
They sure.

00:05.290 --> 00:09.610
And one more type of get request, which we haven't covered yet, which is the query.

00:09.640 --> 00:13.690
It is very important for you to understand that how data comes up with the query.

00:13.780 --> 00:18.100
Now, query is one of the most common thing that you'll be doing, especially in the cases of search

00:18.100 --> 00:18.790
page.

00:18.790 --> 00:23.110
In most of the cases, what you are going to notice that somebody types something into the search bar,

00:23.110 --> 00:28.300
or even if you do that in the Google, it comes up like for example, onto a shopping website, you

00:28.300 --> 00:31.090
say that I want to have a t shirt that says I write code.

00:31.090 --> 00:35.380
So in the search book you just type, I write code and in the back end I have to look through that,

00:35.380 --> 00:36.670
how I'm going to handle that.

00:36.670 --> 00:40.460
But the most important part is that data comes up in the query itself.

00:40.480 --> 00:46.390
For example, there can be a shopping website again, t shirts, and you want to see there's t shirts

00:46.390 --> 00:50.010
which are between the range of ₹300 to ₹800.

00:50.020 --> 00:53.320
These all things are being handled into the query itself.

00:53.350 --> 00:58.780
It is very important for you to understand this query, how it comes up and to take that data, how

00:58.780 --> 00:59.740
we process that data.

00:59.740 --> 01:01.450
That's a different strategy altogether.

01:01.450 --> 01:06.880
But right now let's learn that how we can take those data in the in the variable or something.

01:07.930 --> 01:11.140
So we're going to go ahead and make a copy of this here.

01:11.140 --> 01:12.750
Again, looks nice.

01:12.760 --> 01:18.370
This is, again, a great request, not the first one, because everything is coming from the URL.

01:18.370 --> 01:24.460
And let's call this one as simply this one is going to be coarse query.

01:24.670 --> 01:25.870
Feel free to name it, whatever.

01:25.870 --> 01:28.030
That's just the endpoint that you have to hit.

01:28.090 --> 01:31.510
Now let me go ahead and remove all of this, because we wouldn't be needing this.

01:31.510 --> 01:33.310
We would be getting with that.

01:33.740 --> 01:34.130
Okay.

01:34.210 --> 01:35.840
Now, how are we going to handle this one?

01:35.860 --> 01:40.570
Now, first and foremost, you need to understand that what is the name of the query that you are passing

01:40.570 --> 01:43.300
up whenever you design forms in the HTML?

01:43.300 --> 01:49.150
Remember, everybody says that you make sure that every for every form has some kind of a name associated

01:49.150 --> 01:49.510
with that.

01:49.510 --> 01:53.320
Like name, name, name, username, name, email, name, password.

01:53.320 --> 01:58.630
So that exact name actually is responsible for being a key and value of that.

01:58.630 --> 02:01.930
You'll understand that in a minute, but right now, let's just go with the flow.

02:02.110 --> 02:06.250
So we will be taking two parameters or two parameters in the query itself.

02:06.250 --> 02:10.360
One is going to be location, another one is going to be a device itself.

02:10.360 --> 02:12.850
So let's go ahead and say let location.

02:12.850 --> 02:16.090
So how the location comes up, just like we have requested body.

02:16.090 --> 02:17.950
Similarly, we have requests or params.

02:17.950 --> 02:20.260
Similarly we have got request query here.

02:20.260 --> 02:25.330
I am pretty sure you have read a little bit of the documentation of express by now.

02:25.330 --> 02:27.160
So now we have the location access.

02:27.160 --> 02:30.070
Let's go ahead and access the mobile as well.

02:30.250 --> 02:33.610
Or would be rather it would be accurate to call it as device.

02:33.880 --> 02:35.170
Let's go ahead and have that.

02:35.170 --> 02:40.720
So we're going to say request dot, query, dot device.

02:41.470 --> 02:41.650
Okay.

02:41.920 --> 02:47.470
Once we have this one, you can also go ahead and console.log the entire query itself to see what else

02:47.470 --> 02:48.250
comes in.

02:48.700 --> 02:51.940
But right now, I'm going to go ahead and simply say resort, send.

02:52.120 --> 02:58.990
And in this I'm going to go ahead and pass on an object which will be this location and this device.

02:58.990 --> 02:59.680
There we go.

02:59.680 --> 03:02.800
So we are just taking two parameters and we are just throwing them back.

03:02.800 --> 03:03.760
No big deal.

03:03.850 --> 03:05.080
Let's go ahead and save this.

03:05.080 --> 03:08.200
The important part will come up as we write the documentation for this one.

03:08.200 --> 03:11.110
So let me go ahead and copy this one because it's a cop.

03:12.100 --> 03:12.760
There we go.

03:12.760 --> 03:18.910
And we'll just copy this add course because that's the nearest one and we'll modify that.

03:20.140 --> 03:20.640
Okay.

03:20.740 --> 03:26.020
So how this is going to add up is simply let's go ahead and paste this one, the course query.

03:26.290 --> 03:31.540
And this is the one thing I absolutely love that when you duplicate entirety of the VTS code, any element,

03:31.540 --> 03:36.120
it just doesn't spoil whatever is there in the clipboard of your copy status.

03:36.120 --> 03:37.240
So that's what I love.

03:37.480 --> 03:40.360
Okay, let's go ahead and add this also in the string.

03:40.360 --> 03:41.650
Doesn't really matter.

03:41.650 --> 03:43.330
This is going to be a get request.

03:43.510 --> 03:44.380
Now summary.

03:44.380 --> 03:45.430
This is important.

03:46.420 --> 03:48.040
Let's go ahead and change this one.

03:48.670 --> 03:52.170
Trying to learn about query.

03:52.240 --> 03:54.790
Again, remember, query always goes through the URL.

03:54.940 --> 03:59.680
Now we don't need any of the consumes and produce because we are not doing anything into the request

03:59.680 --> 03:59.950
body.

03:59.950 --> 04:03.100
Although if you keep produces and consume, it's no harm at all.

04:03.100 --> 04:04.300
I'm not going to keep it.

04:04.300 --> 04:06.100
I'll remove this one again.

04:06.100 --> 04:07.180
This is going in the URL.

04:07.180 --> 04:10.570
That means I have to go in the parameters again.

04:10.570 --> 04:12.610
Let's go ahead and add a name to this one.

04:12.610 --> 04:13.660
You don't need to.

04:13.690 --> 04:15.490
We're going to call this one as simply location.

04:15.490 --> 04:16.750
Feel free to change this one.

04:17.080 --> 04:19.120
Interestingly, you have to pass on a name.

04:19.120 --> 04:22.450
Just like previously we said that it's going into params and all of that.

04:22.690 --> 04:26.050
This one is going to go into the query itself and that's it.

04:26.110 --> 04:27.310
Now, is it required?

04:27.310 --> 04:27.700
Yes.

04:27.700 --> 04:31.330
So we are going to go ahead and pass on this required flag as true.

04:31.540 --> 04:33.510
And now let's go ahead and type the schema.

04:33.670 --> 04:37.990
This is going to be the most interesting part, so let's go ahead and define the schema.

04:38.530 --> 04:41.020
Now, I don't want user to just type on anything.

04:41.020 --> 04:44.980
I want to give user some of the selected element that only can be passed through.

04:44.980 --> 04:50.140
So I'm going to go ahead and say that this is going to be of type string, although this is a string,

04:50.290 --> 04:55.300
but as soon as just after the string or any data type that you go ahead, you can actually go ahead

04:55.300 --> 04:57.430
and give him the option of enemies.

04:57.430 --> 05:01.360
Enemies, as I mentioned, always I always give the example of airplanes.

05:01.360 --> 05:03.070
There are three options only similar here.

05:03.070 --> 05:09.550
I'm going to go ahead and say the options are Delhi, London, come on, London.

05:09.550 --> 05:12.280
And of course, my favourite, which is my own city.

05:12.400 --> 05:14.920
Okay, so this is all the options that you have got.

05:14.950 --> 05:18.520
Now similar to this, we can go ahead and provide another of the name.

05:18.520 --> 05:20.740
This is just one parameter we have defined.

05:20.740 --> 05:27.100
But remember into the index file we are receiving or expecting at least one more, which is device.

05:27.400 --> 05:31.420
So what we can do is remember this is all the first parameter.

05:31.420 --> 05:33.610
So I'm going to go ahead and duplicate this one.

05:33.820 --> 05:38.110
The first one is location, the second one is going to be device.

05:38.290 --> 05:41.290
So it is also going to be passed on in the query itself.

05:41.500 --> 05:44.980
It is also required the schema string, but the options get changed.

05:45.220 --> 05:50.020
This time you are having device as web or the mobile.

05:50.290 --> 05:55.240
So whatever I select, I expect that that is going to be passed on to me in the response.

05:55.240 --> 05:58.480
The response this time is also not going to be boolean.

05:58.480 --> 06:00.010
This is more like an object.

06:00.010 --> 06:01.420
So let's go ahead and change that.

06:01.570 --> 06:02.590
This is an object.

06:02.590 --> 06:09.340
As soon as I write object, I have to write properties and the properties I'm going to go ahead and

06:09.340 --> 06:16.360
grab an ID which is going to be of ID will be off type string.

06:16.960 --> 06:19.840
I can actually go ahead and copy this to save us some time.

06:19.840 --> 06:21.790
So let's go a scroll a little bit.

06:22.510 --> 06:23.250
Yep.

06:23.260 --> 06:25.150
Are we passing on this exact.

06:26.230 --> 06:27.130
Not like that.

06:27.130 --> 06:28.510
Let me go back up here.

06:28.660 --> 06:32.650
So we are going to have the ID, but not having ID.

06:32.650 --> 06:35.920
What we are passing on, we're passing on the location and the device.

06:35.920 --> 06:37.960
So both of them are coming up as a string.

06:38.230 --> 06:43.300
So let's call this one as simply name as a string and let's go ahead and make a duplicate of this one.

06:45.100 --> 06:47.690
Name and this is going to be a value which is of type string.

06:47.710 --> 06:49.930
Hopefully things are okay.

06:49.960 --> 06:50.520
Not sure.

06:50.530 --> 06:51.130
Hopefully.

06:51.460 --> 06:51.700
Okay.

06:51.700 --> 06:53.790
Let's go back on to the browser.

06:53.800 --> 06:57.100
Hit a reload and there we go.

06:57.100 --> 06:59.620
We have another get request which is the course query.

06:59.620 --> 07:02.020
And notice here, this time we cannot write it.

07:02.020 --> 07:05.170
Previously when we were sending the course ID, we were able to write it.

07:05.170 --> 07:09.790
You can also restrict this with the enum that these are the only options that you can select and pass

07:09.790 --> 07:10.180
on.

07:10.360 --> 07:13.560
So here we are saying the course query, both of them are required.

07:13.570 --> 07:16.570
So you are saying that this is how this is going to come in.

07:16.570 --> 07:18.790
So value is going to be name and value.

07:18.790 --> 07:20.470
So this is how it's going to come in.

07:21.190 --> 07:22.600
Not really accurate.

07:23.290 --> 07:24.640
It can be a little bit modified.

07:24.640 --> 07:25.960
But let me show you that.

07:25.990 --> 07:29.680
Most important thing is let's try it out and see the URL.

07:29.980 --> 07:33.810
So let's just say my location is Jaipur and I'm looking on Mobile.

07:33.820 --> 07:36.330
Hypothetically, of course, let's execute this.

07:36.340 --> 07:40.060
Now notice here that this is how the URL actually goes in.

07:40.090 --> 07:42.580
You simply name API V1 and the course query.

07:42.580 --> 07:48.850
Then notice here it's a question mark and it says Location equals Jaipur and the device equals mobile

07:48.850 --> 07:50.920
and we are receiving it properly.

07:50.920 --> 07:55.780
So in the request body we are sending a location is Jaipur and the device is mobile.

07:55.780 --> 07:58.300
So we can actually modify this a little bit.

07:58.750 --> 08:05.590
So we're going to say that this is going to be location which is going to come up as a string and the

08:05.590 --> 08:07.570
device which is going to come up as a string.

08:07.570 --> 08:10.000
So I think this makes a little bit more sense.

08:10.060 --> 08:15.760
Reload that and open this up and yep, this now makes a little bit more sense.

08:15.940 --> 08:18.070
Okay, so go ahead, play around a little bit more.

08:18.070 --> 08:23.440
And now you have learned that how you can handle your queries as well as how you can pass on all the

08:23.470 --> 08:27.760
how you can handle the queries in the back end as well and how you can use them in the swagger as well.

08:27.790 --> 08:28.810
Quite an interesting one.

08:28.810 --> 08:30.760
Let's go ahead and catch up in the next video.
