WEBVTT

00:03.730 --> 00:04.630
Hated everyone.

00:04.700 --> 00:09.760
Fischer And in this video, we're going to create a very simple, basic route which returns a simple

00:09.760 --> 00:10.120
string.

00:10.120 --> 00:11.740
It can return an object as well.

00:11.740 --> 00:12.790
Eventually it will.

00:12.820 --> 00:14.980
Now, this will serve to purposes.

00:14.980 --> 00:19.270
The first one, obviously, we are going to learn how to write the documentation for it, but it will

00:19.270 --> 00:24.100
also give you an opportunity to explore the documentation of EXPRESS because we'll be handling multiple

00:24.100 --> 00:27.780
requests as well as we'll be handling a multiple responses as well.

00:27.790 --> 00:32.620
A lot of data is going to come into our servers and a lot of data will be going out of the servers in

00:32.620 --> 00:38.290
multiple formats strings, objects, arrays, files, a whole lot of things that are going to be there.

00:38.290 --> 00:44.110
So please don't be shy, go on to the Express documentation and just go through a lot of stuff into

00:44.350 --> 00:45.400
request and response.

00:45.400 --> 00:49.390
It's one of the most easiest library to understand after this course, of course.

00:49.390 --> 00:51.310
So make sure to keep an eye on that.

00:51.550 --> 00:56.170
Now, moving on, let's go into the index and there are a couple of things that we'll be doing.

00:56.170 --> 01:01.750
The first thing that we're going to do is I will be creating a simple array and now this array is going

01:01.750 --> 01:02.650
to be later on use.

01:02.650 --> 01:06.640
So make sure you don't use constant this one because we'll be modifying this array.

01:06.760 --> 01:11.470
Let's go ahead and call this one as simply courses because this is going to be an array of courses.

01:11.470 --> 01:14.230
Now inside this courses, I'll have an object.

01:14.230 --> 01:16.930
Now inside this object, let's add a couple of properties.

01:16.930 --> 01:21.910
For example, we'll be putting up ID, which will be one one and make sure you also follow closely in

01:21.910 --> 01:22.510
this one.

01:22.660 --> 01:24.460
Once you are done with this, you can change anything.

01:24.460 --> 01:26.200
But right now, please follow closely.

01:26.200 --> 01:28.540
This one will be calling this one as name.

01:28.540 --> 01:32.710
So we're going to call this one as a learn, react, react.

01:32.720 --> 01:35.950
JS And after that we'll be going for a price.

01:36.220 --> 01:38.740
Now, for the price, we'll be just saying to 99.

01:38.740 --> 01:40.120
Now I have a variety here.

01:40.120 --> 01:41.970
We have string and we have some numbers.

01:41.970 --> 01:42.880
So all going on.

01:42.880 --> 01:44.500
Let's go ahead and put up a comma.

01:44.500 --> 01:48.400
Now, I need a couple of copies of this, so I'm going to go ahead and bring two more.

01:48.520 --> 01:49.930
And again, I'm using shortcut.

01:49.930 --> 01:51.250
I'm kind of used to with that.

01:51.250 --> 01:54.790
In case you are not just make sure you go ahead and copy paste that.

01:54.790 --> 01:56.110
So this one is going to be two too.

01:56.140 --> 01:57.460
This one is going to be three.

01:57.460 --> 01:57.970
Three.

01:58.060 --> 01:59.590
Let's go ahead and add some more.

01:59.590 --> 02:02.440
So we're going to say, hey, probably you want to learn Angular.

02:03.620 --> 02:04.500
There we go.

02:04.520 --> 02:08.240
Or probably you want to learn something else, maybe Django or something else.

02:08.330 --> 02:13.040
Let's change the pricing to probably 399, 499, something like that.

02:13.040 --> 02:13.880
Whatever you want.

02:14.060 --> 02:15.140
Doesn't really matter.

02:15.170 --> 02:17.210
We will be using this array later on.

02:17.210 --> 02:19.260
So right now you can just keep it as it is.

02:19.280 --> 02:24.090
We'll still keep our route as it is, but we need to create something different of a route.

02:24.110 --> 02:26.870
So let's go ahead and copy paste this one.

02:27.440 --> 02:33.080
Now, one important thing is that we have defined our server as the URLs up here.

02:33.080 --> 02:38.870
So inside the server we have mentioned the URL that we are going to use is going to be V one, so http

02:38.900 --> 02:42.200
and then localhost 4000 API and the version.

02:42.200 --> 02:46.890
So make sure this is not just a fictitious URL or this is just not an ornament there.

02:46.910 --> 02:49.040
This will be used while making the request.

02:49.040 --> 02:50.390
That's why we call them as server.

02:50.390 --> 02:52.520
So don't think that these are just ornaments.

02:52.850 --> 02:55.310
Whatever you are going to define is automatically going to come.

02:55.310 --> 02:57.020
And no, it doesn't work like that.

02:57.290 --> 02:58.370
Okay, moving on.

02:58.970 --> 03:02.720
So as we have mentioned that this is going to be API slash V one.

03:02.720 --> 03:04.070
So we have to mention that.

03:04.070 --> 03:09.830
And then if somebody hits the root of AE, then we are going to simply send a response which says hello

03:09.830 --> 03:10.820
from AE.

03:11.420 --> 03:14.350
So hello from AE Docs.

03:14.360 --> 03:14.620
Yeah.

03:14.660 --> 03:16.190
Just to make it a little bit different.

03:16.790 --> 03:19.160
You can also send most of the other objects as well.

03:19.160 --> 03:21.770
But right now this is all what we want to do.

03:22.100 --> 03:26.270
Let's go into the swagger and see that how we actually can write all of this.

03:26.390 --> 03:31.520
Now, one thing that confuses a lot of people that no matter what kind of roots you are doing, maybe

03:31.520 --> 03:36.950
for products, for users, for orders, for categories, for courses, whatever, it all comes into

03:36.950 --> 03:39.320
just one umbrella, which is known as paths.

03:39.320 --> 03:39.680
Yes.

03:39.680 --> 03:42.380
This is the only drawback of the yaml.

03:42.470 --> 03:43.010
Yes.

03:43.010 --> 03:47.460
There are some CLI tools given by the YAML to actually combine all of the YAML files.

03:47.480 --> 03:48.670
A lot of people do that.

03:48.680 --> 03:53.150
That will be a little bit out of the scope of this course because we just need the bare minimum basics

03:53.150 --> 03:54.770
and you can explore that on your own.

03:55.010 --> 04:01.370
Now how this path is going to look like, I'll say that slash AE because remember in the servers I have

04:01.370 --> 04:05.360
already mentioned, it's slash slash API slash V1.

04:05.360 --> 04:06.920
So that's what we are following up here.

04:07.040 --> 04:12.050
Now notice here, once I have given that this is going to be my root, then I have to mention that what

04:12.050 --> 04:14.780
kind of root this is going to be, this is going to be get or post.

04:14.780 --> 04:18.830
And for each of that path, if I want to write, get post, I have to go through like this.

04:18.830 --> 04:22.760
So if I have to get all the properties of get, then if I have a post here.

04:22.760 --> 04:26.360
So I'll come back and write post up here and all the further properties down there.

04:26.390 --> 04:28.970
Right now let's go ahead and worry just about the get.

04:29.150 --> 04:31.910
Now inside the get, I will add a summary.

04:31.910 --> 04:35.910
So let's go ahead and add a summary in the writing documentation part.

04:35.930 --> 04:38.420
This is really tricky and you might want to follow a standard.

04:38.420 --> 04:40.280
It's up to you how you want to say that.

04:40.280 --> 04:49.910
We're going to simply say return a returns agreed message from AE.

04:49.940 --> 04:51.620
Okay, that sounds a good summary.

04:51.620 --> 04:56.000
Now after that comes up is the most important part, which is responses.

04:56.120 --> 04:59.630
Now responses can be multiple, the responses can be 200.

04:59.660 --> 05:00.830
Yes, you can write it in quotes.

05:00.830 --> 05:02.660
You can write it in without code as well.

05:02.690 --> 05:09.380
There can be multiple responses like 300, 400, maybe you want to describe 500 as well.

05:09.380 --> 05:12.200
It's all up to you what you define and how you're going to define.

05:12.200 --> 05:14.870
Let me define one here and then show you.

05:14.870 --> 05:18.350
Then I'll remove the 500 because it's eventually going to get too much.

05:18.500 --> 05:19.040
Okay.

05:19.400 --> 05:21.080
The first thing is description.

05:21.080 --> 05:23.750
So you go ahead and simply say what is going to be the description?

05:23.750 --> 05:27.440
All good and success.

05:27.440 --> 05:30.260
Usually this is like little bit more of a description type.

05:30.260 --> 05:31.480
So this is what we do.

05:31.490 --> 05:36.110
Now, apart from this, you can also mention that what is the type of content that will be coming up

05:36.110 --> 05:36.620
here?

05:37.340 --> 05:42.380
So let's go ahead and say that this content is going to be coming up, is going to be a type of application

05:42.380 --> 05:49.130
slash JSON, although we are not sending the JSON, but we will modify our route in a minute and then

05:49.130 --> 05:50.960
we can also define our scheme.

05:50.960 --> 05:52.940
Now this not scheme schema.

05:53.390 --> 05:59.000
So what the schema is going to be that I am returning a type of string, we will have multiple eventually.

05:59.000 --> 06:00.350
So don't do worry on that part.

06:00.350 --> 06:03.230
And we can also define an example here.

06:05.320 --> 06:08.170
So for example, let's just say my string.

06:08.650 --> 06:13.690
As soon as I saved this, I would like to actually copy paste this description to others as well, so

06:13.690 --> 06:15.640
that we have at least something to look on.

06:16.120 --> 06:17.320
And there we go.

06:17.590 --> 06:19.270
And this one is going to be.

06:21.160 --> 06:28.930
Bad request and this one is going to be internal server error.

06:29.860 --> 06:30.790
Quite a lot of stuff.

06:30.790 --> 06:35.980
So let's go up here and let me go back onto the browser swagger and hit a reload.

06:36.250 --> 06:39.550
Now you can see that this is the first one that we have seen so far.

06:39.580 --> 06:40.960
This is how it looks like.

06:40.960 --> 06:42.820
So we can see we have a get request.

06:42.820 --> 06:44.650
It will be on the path slash ae.

06:44.650 --> 06:47.440
But remember right now you haven't computed this one.

06:47.440 --> 06:52.450
So if you try to just go ahead and try it out, it's not going to probably not going to work much because

06:52.450 --> 06:55.390
you're you are is undefined and this is not how it's going to work.

06:55.390 --> 07:01.660
So you have to every time select the V one again it's not coming up so v one and then you have to say

07:01.660 --> 07:03.820
that, hey, I have to use the HTTP.

07:03.820 --> 07:05.680
You can also mention the default one.

07:05.920 --> 07:08.680
We will be seeing that how we can do that later on.

07:08.950 --> 07:10.330
Right now, this is all what we have got.

07:10.330 --> 07:12.370
As soon as I go ahead and hit cancel first.

07:12.370 --> 07:17.290
So you need to hit try out every single time and hit click on execute there.

07:17.290 --> 07:21.700
Now this request goes to http localhost API V1 and slash AE.

07:21.700 --> 07:23.380
So this is the part that is coming up.

07:23.380 --> 07:29.650
Our message is also coming up nicely returns a greeting message from AE and we get a response body which

07:29.650 --> 07:31.630
says hello from the AE docs.

07:31.630 --> 07:33.460
We also see some of the response header.

07:33.460 --> 07:38.740
Remember in the docs of Express, I mentioned that you can also set some headers via the back end.

07:38.740 --> 07:41.620
This is exactly how you do this and this is how you get it.

07:41.650 --> 07:44.110
Now in here we see that all good success.

07:44.110 --> 07:47.350
These are response code that what is going to happen and how it works.

07:47.350 --> 07:52.240
Since in the response code we have mentioned that the media type that is coming up is the application

07:52.240 --> 07:52.600
JSON.

07:52.600 --> 07:55.990
That's why it's coming up and all the basic schemas.

07:55.990 --> 07:59.230
Now good thing is notice here in the example value there is a schema.

07:59.230 --> 08:03.970
You can click on this and it will give you that exact schema that is coming up like string and example

08:03.970 --> 08:05.080
is going to be a string.

08:05.080 --> 08:09.190
So this actually gives the user an idea that what kind of response I'm going to get back.

08:09.190 --> 08:13.990
Of course the user can actually execute, but writing a schema is always a good idea in case your application

08:13.990 --> 08:16.660
is too much heavily driven on this entire thing.

08:16.900 --> 08:20.710
Now coming up, back to the part, we will be working on it a little bit.

08:20.710 --> 08:22.600
One more thing I would like to mention here.

08:23.260 --> 08:29.320
You can see that we have this default AE So how you can change this default, this is the basic and

08:29.320 --> 08:32.710
I know this is not too much visible here, but this is all grayed out.

08:32.710 --> 08:36.070
So this is how you actually group all of the requests together.

08:36.070 --> 08:39.310
So what you can do, you can actually tag these requests.

08:39.310 --> 08:43.660
So just after the get request, I can go ahead and hit the tag.

08:43.660 --> 08:48.490
So I'm going to say tags and let's go ahead and call this one as.

08:49.650 --> 08:50.400
String.

08:51.030 --> 08:54.720
Now you can get this tag onto multiple other paths as well.

08:54.720 --> 08:59.760
And as soon as you are going to do this and let me hit a refresh and now notice a string.

08:59.760 --> 09:05.640
So all the other requests that are related to this particular tag string, they will not go further

09:05.640 --> 09:10.260
down in the road, but actually automatically will come up into this group, which is the string group.

09:10.290 --> 09:15.660
I will also explain this a little bit more in depth later on, but I guess this is all it for now.

09:15.660 --> 09:17.790
And let's go back into the next video.
