WEBVTT

00:03.790 --> 00:04.660
Hey there, everyone.

00:04.780 --> 00:06.760
They sure and welcome to the video.

00:06.760 --> 00:09.520
And we are trying to write swagger documentation.

00:09.730 --> 00:12.400
Now, so far in the course we have made only the gate request.

00:12.400 --> 00:17.080
This is also going to be a get request, but this is going to be a bit of a different type.

00:17.110 --> 00:22.330
Now in this one, we want to pass on something to the database or you can say backend in this case.

00:22.330 --> 00:26.280
And based on that particular value, we will be getting some result.

00:26.290 --> 00:29.860
Now there are a variety of ways of how you can pass on some information to the backend.

00:29.860 --> 00:35.800
It can go through the URL or also known as parameters or also known as path, all these names for the

00:35.800 --> 00:36.580
single thing.

00:36.580 --> 00:42.700
You can also pass on some information via a proper parameters like forms and requests, body and all

00:42.700 --> 00:43.240
of that.

00:43.240 --> 00:47.680
So we're going to start with the very basic one, which is passing information in the route itself,

00:47.680 --> 00:49.030
also known as PATH.

00:49.180 --> 00:53.920
So let's first go ahead and open up index for us and go ahead and write something for it.

00:53.950 --> 00:55.420
So we're going to simply go ahead.

00:55.420 --> 00:56.800
We can actually copy this one.

00:56.800 --> 00:59.770
So I'm going to go ahead and bring all of this.

00:59.770 --> 01:00.490
There we go.

01:01.300 --> 01:01.520
Okay.

01:01.630 --> 01:07.090
So how this is going to work, so this is going to be called as course or they would rather like to

01:07.090 --> 01:10.720
call it as my course, feel free to name it anything, whatever you like.

01:10.720 --> 01:14.890
And then we expect that some information will come up into the URL.

01:14.920 --> 01:20.950
The way how we do it is put up a colon and then we can simply mention this as course ID now you can

01:20.950 --> 01:23.470
name it course id id however you like.

01:23.470 --> 01:25.030
This is how simply we do it.

01:25.060 --> 01:26.650
Now let's go ahead and remove this one.

01:26.650 --> 01:32.440
Now what we're going to do is we're going to look into our array will match if there is any course ID

01:32.440 --> 01:33.310
related to this.

01:33.310 --> 01:35.350
If it matches, we're going to return it back.

01:35.350 --> 01:36.190
Really simple.

01:36.190 --> 01:40.450
So all we got to do is simply take my course out of it.

01:40.810 --> 01:41.440
Cost.

01:41.440 --> 01:42.400
Not course.

01:42.400 --> 01:43.180
There we go.

01:44.260 --> 01:45.130
Come on.

01:46.240 --> 01:47.560
There is a lot of mistake here.

01:48.550 --> 01:49.210
There we go.

01:50.140 --> 01:52.090
Okay, so how are we going to find this one out?

01:52.090 --> 01:57.100
First, we need to look out for our courses array and in that we can simply use a find method.

01:57.370 --> 02:01.930
Definitely you can go ahead and use your maps and filter and anything else that you are comfortable

02:01.930 --> 02:04.600
with in this case, I think find makes a lot of sense.

02:04.600 --> 02:05.890
It's really easy one.

02:05.980 --> 02:08.320
So find again loops through with all the values.

02:08.320 --> 02:11.170
So let's call this each value as course.

02:11.170 --> 02:16.150
And once you go ahead and loop through it, then all you got to do is this course, individual course,

02:16.150 --> 02:23.710
which is an object, has a property of ID if it matches with the ID that is being provided by the URL.

02:23.710 --> 02:29.410
And you cannot just go ahead and write course ID like this because this is not how you access the URL

02:29.410 --> 02:30.940
in the express.

02:31.360 --> 02:38.620
In this case, what we got to do is we have to say request dot params dot cause id.

02:39.910 --> 02:40.960
There we go.

02:41.500 --> 02:46.150
Now in this case, remember, the course ID is exactly coming up from the URL and in order to access

02:46.150 --> 02:48.940
it from the URL, you have to say request params.

02:48.940 --> 02:57.700
Now this will obviously fill up the my course available and all we got to do after that is rez dot send

02:57.700 --> 03:00.340
and we are going to send this my course.

03:00.340 --> 03:00.940
There we go.

03:01.090 --> 03:06.190
So this is pretty easy in case you want to test out, you can use Thunder client or any other similar

03:06.190 --> 03:07.150
situation like this.

03:07.150 --> 03:12.450
So let's go ahead and try to use this and let's go ahead and pass on this to two.

03:12.550 --> 03:14.350
So let's open up the tender client.

03:14.350 --> 03:17.260
I want to make a new request, which is going to be.

03:18.270 --> 03:21.980
HTTP, colon, slash, slash.

03:21.990 --> 03:23.730
And by the way, this is a simple add on.

03:23.770 --> 03:28.110
You can just go ahead and install this extension look or you can use postman also.

03:28.110 --> 03:30.540
So local host Colon 4000.

03:30.810 --> 03:32.790
I know this is like really small.

03:33.090 --> 03:33.720
Yeah.

03:33.780 --> 03:35.770
This is now much more visible.

03:35.790 --> 03:38.320
4000 slash and there we go.

03:38.340 --> 03:41.910
I accidentally added two slashes, so let's go ahead and remove that.

03:43.120 --> 03:43.710
There we go.

03:43.720 --> 03:45.610
Make sure you are also cautious about this.

03:45.610 --> 03:50.560
And once you do this, after that, we're going to go ahead and simply use two two for the course ID.

03:50.590 --> 03:51.820
Let's go ahead and send this.

03:51.820 --> 03:54.400
And this gives me the course which is coming back.

03:54.400 --> 04:00.400
As with the ID, two, two, I can go ahead and write three, three and let's send this up and it gives

04:00.400 --> 04:01.450
me the next course.

04:01.450 --> 04:06.220
So we get the idea of our API is working fine and this is two too much zoomed in.

04:06.220 --> 04:06.940
There we go.

04:07.090 --> 04:07.560
Okay.

04:08.170 --> 04:12.940
Now, once we are done with this, we obviously need to write documentation for this particular route.

04:12.940 --> 04:14.710
So let's go ahead and address this one.

04:14.710 --> 04:18.790
This is slash my core slash course ID going up into the swagger.

04:18.820 --> 04:20.290
We are going to copy this route.

04:20.290 --> 04:25.240
So let's go ahead and select all of this, make a copy, and now let's change this one.

04:25.240 --> 04:28.600
So this one is actually my.

04:29.550 --> 04:30.230
Of course.

04:30.240 --> 04:33.330
And once you have this course, then we are taking something in the parameter.

04:33.350 --> 04:35.070
So this is how we represent it.

04:35.070 --> 04:37.230
So course ID goes like this.

04:37.320 --> 04:38.730
Now this is a get tag.

04:39.030 --> 04:41.670
We can combine it with array.

04:41.700 --> 04:45.090
Let's just say it's not really ideal, but let's go ahead and do this.

04:45.420 --> 04:47.520
It is not going to return all the courses.

04:47.520 --> 04:54.360
It is going to return course based on request ID.

04:54.780 --> 04:55.890
That's what it does.

04:55.890 --> 04:56.280
Now.

04:56.280 --> 05:01.740
Also, so far we have only talked about responses, but this time we need to talk about how we can send

05:01.740 --> 05:02.820
some information.

05:02.820 --> 05:06.330
Usually most of the information is sent through parameters.

05:06.960 --> 05:10.050
If I can write that para meters.

05:10.050 --> 05:10.680
There we go.

05:10.980 --> 05:12.600
Okay, so how do we do this?

05:12.600 --> 05:16.890
Parameters can be done and being passed can be passed on through variety of things.

05:16.890 --> 05:18.000
First, let's name it.

05:18.000 --> 05:21.180
Name is not at all compulsory, but I still like to give it.

05:21.510 --> 05:24.510
I'll show you where this name comes up in a minute.

05:24.510 --> 05:30.180
So once we have this name, the most important part is in now where your information is going to be

05:30.180 --> 05:30.720
passing through.

05:30.750 --> 05:32.250
Is it going to be in the query?

05:32.280 --> 05:33.690
Is it going to be in the path?

05:33.840 --> 05:38.160
Yes, we call you out as spot and there are a couple of other places that we eventually are going to

05:38.160 --> 05:38.910
explore.

05:39.240 --> 05:40.470
And is it required?

05:40.480 --> 05:42.000
Yes, this is very much required.

05:42.000 --> 05:44.730
So we're going to mark the required flag as true.

05:45.390 --> 05:48.570
And we will also say that there are some default values.

05:48.570 --> 05:52.650
If the user doesn't pass on anything or write anything, 22 is going to be default one.

05:52.920 --> 05:56.700
And then we are also going to say, what schema is it going to return?

05:56.700 --> 06:01.920
The schema is definitely an object that we are coming up for that.

06:01.920 --> 06:06.090
So let's go ahead and say that the schema that is coming up is going to be an object.

06:06.090 --> 06:11.730
You can write string as well, but this is what we are writing and once we write the object, you already

06:11.730 --> 06:14.190
know that we need to type all of this.

06:14.190 --> 06:16.860
So let's go ahead and grab all of this, copy that.

06:17.160 --> 06:19.740
And we are going to go ahead and paste this one.

06:20.280 --> 06:24.840
And again, make sure the type and property are on the same indentation, just like we have done it

06:24.840 --> 06:25.080
here.

06:25.080 --> 06:30.120
We are going to receive an ID name and price and this is too much indented.

06:30.120 --> 06:32.100
So let's go ahead and shift them back.

06:32.340 --> 06:33.030
There we go.

06:33.030 --> 06:33.990
Looking nice.

06:34.230 --> 06:36.480
Now coming up onto the responses.

06:37.230 --> 06:37.950
My bad.

06:38.160 --> 06:39.870
This is not like this.

06:39.870 --> 06:41.400
Sorry, this is my bad.

06:41.400 --> 06:42.600
We are not having property.

06:42.600 --> 06:45.540
This is the scheme of what you are sending and this is not an object.

06:45.540 --> 06:51.480
This is actually an a string to just God that could have been done a little bit wrong there.

06:51.480 --> 06:55.740
But hey, thankfully notice on time response is going to be all good success.

06:55.740 --> 07:04.650
The schema that we are turning is not an array, this is an object and we don't have items this time.

07:04.650 --> 07:06.480
So let's go ahead and remove this.

07:08.030 --> 07:09.560
We also don't need this one.

07:09.560 --> 07:12.110
So we're going to go ahead and remove this one.

07:12.680 --> 07:17.690
This is going to have the properties just like we saw about these properties, but it needs to be indented

07:17.690 --> 07:18.260
properly.

07:18.260 --> 07:20.870
So let's go ahead and move this up here.

07:21.380 --> 07:24.020
This can also be indented a little bit better.

07:24.050 --> 07:28.710
Again, these documentation may have some errors, but you've got to fix them up.

07:28.730 --> 07:30.110
Let's go ahead and hit a reload.

07:31.490 --> 07:34.340
And we see that area is now having two of these ones.

07:34.340 --> 07:39.770
So let's go ahead and mix it up with the string so that it's much more easier to actually see.

07:40.070 --> 07:44.420
So instead of array, we're going to go ahead and say, hey, you go ahead and get mixed with strings.

07:44.420 --> 07:47.090
Let's go ahead, go back, hit to reload.

07:47.090 --> 07:47.740
And there we go.

07:47.750 --> 07:50.900
Now it's mixed up with the string, so easy with the tags.

07:50.900 --> 07:52.850
Now let's analyze this a little bit.

07:52.850 --> 07:56.180
So first, the default values in all are all good.

07:56.210 --> 07:57.470
Remember we gave it a name?

07:57.470 --> 08:00.380
Of course ID this is exactly coming up from here.

08:00.380 --> 08:05.270
So the parameter when you say course ID, this is exactly coming up here in the name section.

08:05.270 --> 08:07.940
It is a string, it is a default, value is 22.

08:07.940 --> 08:09.950
And notice here it says marked as required.

08:09.950 --> 08:11.270
So yes, this is required.

08:11.270 --> 08:12.710
The default value is 22.

08:12.740 --> 08:15.200
Right now it's giving me this icon that you are not allowed.

08:15.200 --> 08:17.450
It's because I didn't hit the try it out.

08:17.450 --> 08:22.640
As soon as you hit the try it out then you are allowed to enter any values and all good success.

08:22.640 --> 08:24.650
We have already discussed quite in detail on that.

08:24.650 --> 08:27.290
So let's go ahead and hit execute and there we go.

08:27.290 --> 08:28.610
As soon as you execute.

08:28.970 --> 08:32.120
Now notice it says my course 22.

08:32.120 --> 08:34.580
So we are returning all the bad stuff up here.

08:34.580 --> 08:35.720
So this is something wrong.

08:35.720 --> 08:37.760
Let's go ahead and see that how this is going on.

08:37.970 --> 08:39.680
Yep, I missed a slash.

08:39.680 --> 08:42.500
So see, errors are a part of the development.

08:42.530 --> 08:44.120
Let's go ahead and hit a reload.

08:44.480 --> 08:48.320
Let's see what is going on wrong and let's try it out one more time.

08:48.320 --> 08:52.400
Execute this and this time we are getting a proper course ID back.

08:52.400 --> 08:57.860
Let's go ahead and try it one more time with one one execute that and we are getting react awesome looks

08:57.860 --> 08:58.220
great.

08:58.220 --> 08:59.060
Looks fine.

08:59.060 --> 09:04.850
So now that you know that how you can handle the get request but you can also you have also the information

09:04.850 --> 09:10.010
about how we can send parameters or we can send some information to the back end and can receive some

09:10.010 --> 09:10.520
data back.

09:10.520 --> 09:14.210
So parameters and responses are the new thing that we have learned in this video.

09:14.240 --> 09:16.520
Let's go ahead and catch up in the next video.
