Hated everyone.
Fischer And in this video, we're going to create a very simple, basic route which returns a simple
string.
It can return an object as well.
Eventually it will.
Now, this will serve to purposes.
The first one, obviously, we are going to learn how to write the documentation for it, but it will
also give you an opportunity to explore the documentation of EXPRESS because we'll be handling multiple
requests as well as we'll be handling a multiple responses as well.
A lot of data is going to come into our servers and a lot of data will be going out of the servers in
multiple formats strings, objects, arrays, files, a whole lot of things that are going to be there.
So please don't be shy, go on to the Express documentation and just go through a lot of stuff into
request and response.
It's one of the most easiest library to understand after this course, of course.
So make sure to keep an eye on that.
Now, moving on, let's go into the index and there are a couple of things that we'll be doing.
The first thing that we're going to do is I will be creating a simple array and now this array is going
to be later on use.
So make sure you don't use constant this one because we'll be modifying this array.
Let's go ahead and call this one as simply courses because this is going to be an array of courses.
Now inside this courses, I'll have an object.
Now inside this object, let's add a couple of properties.
For example, we'll be putting up ID, which will be one one and make sure you also follow closely in
this one.
Once you are done with this, you can change anything.
But right now, please follow closely.
This one will be calling this one as name.
So we're going to call this one as a learn, react, react.
JS And after that we'll be going for a price.
Now, for the price, we'll be just saying to 99.
Now I have a variety here.
We have string and we have some numbers.
So all going on.
Let's go ahead and put up a comma.
Now, I need a couple of copies of this, so I'm going to go ahead and bring two more.
And again, I'm using shortcut.
I'm kind of used to with that.
In case you are not just make sure you go ahead and copy paste that.
So this one is going to be two too.
This one is going to be three.
Three.
Let's go ahead and add some more.
So we're going to say, hey, probably you want to learn Angular.
There we go.
Or probably you want to learn something else, maybe Django or something else.
Let's change the pricing to probably 399, 499, something like that.
Whatever you want.
Doesn't really matter.
We will be using this array later on.
So right now you can just keep it as it is.
We'll still keep our route as it is, but we need to create something different of a route.
So let's go ahead and copy paste this one.
Now, one important thing is that we have defined our server as the URLs up here.
So inside the server we have mentioned the URL that we are going to use is going to be V one, so http
and then localhost 4000 API and the version.
So make sure this is not just a fictitious URL or this is just not an ornament there.
This will be used while making the request.
That's why we call them as server.
So don't think that these are just ornaments.
Whatever you are going to define is automatically going to come.
And no, it doesn't work like that.
Okay, moving on.
So as we have mentioned that this is going to be API slash V one.
So we have to mention that.
And then if somebody hits the root of AE, then we are going to simply send a response which says hello
from AE.
So hello from AE Docs.
Yeah.
Just to make it a little bit different.
You can also send most of the other objects as well.
But right now this is all what we want to do.
Let's go into the swagger and see that how we actually can write all of this.
Now, one thing that confuses a lot of people that no matter what kind of roots you are doing, maybe
for products, for users, for orders, for categories, for courses, whatever, it all comes into
just one umbrella, which is known as paths.
Yes.
This is the only drawback of the yaml.
Yes.
There are some CLI tools given by the YAML to actually combine all of the YAML files.
A lot of people do that.
That will be a little bit out of the scope of this course because we just need the bare minimum basics
and you can explore that on your own.
Now how this path is going to look like, I'll say that slash AE because remember in the servers I have
already mentioned, it's slash slash API slash V1.
So that's what we are following up here.
Now notice here, once I have given that this is going to be my root, then I have to mention that what
kind of root this is going to be, this is going to be get or post.
And for each of that path, if I want to write, get post, I have to go through like this.
So if I have to get all the properties of get, then if I have a post here.
So I'll come back and write post up here and all the further properties down there.
Right now let's go ahead and worry just about the get.
Now inside the get, I will add a summary.
So let's go ahead and add a summary in the writing documentation part.
This is really tricky and you might want to follow a standard.
It's up to you how you want to say that.
We're going to simply say return a returns agreed message from AE.
Okay, that sounds a good summary.
Now after that comes up is the most important part, which is responses.
Now responses can be multiple, the responses can be 200.
Yes, you can write it in quotes.
You can write it in without code as well.
There can be multiple responses like 300, 400, maybe you want to describe 500 as well.
It's all up to you what you define and how you're going to define.
Let me define one here and then show you.
Then I'll remove the 500 because it's eventually going to get too much.
Okay.
The first thing is description.
So you go ahead and simply say what is going to be the description?
All good and success.
Usually this is like little bit more of a description type.
So this is what we do.
Now, apart from this, you can also mention that what is the type of content that will be coming up
here?
So let's go ahead and say that this content is going to be coming up, is going to be a type of application
slash JSON, although we are not sending the JSON, but we will modify our route in a minute and then
we can also define our scheme.
Now this not scheme schema.
So what the schema is going to be that I am returning a type of string, we will have multiple eventually.
So don't do worry on that part.
And we can also define an example here.
So for example, let's just say my string.
As soon as I saved this, I would like to actually copy paste this description to others as well, so
that we have at least something to look on.
And there we go.
And this one is going to be.
Bad request and this one is going to be internal server error.
Quite a lot of stuff.
So let's go up here and let me go back onto the browser swagger and hit a reload.
Now you can see that this is the first one that we have seen so far.
This is how it looks like.
So we can see we have a get request.
It will be on the path slash ae.
But remember right now you haven't computed this one.
So if you try to just go ahead and try it out, it's not going to probably not going to work much because
you're you are is undefined and this is not how it's going to work.
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
that, hey, I have to use the HTTP.
You can also mention the default one.
We will be seeing that how we can do that later on.
Right now, this is all what we have got.
As soon as I go ahead and hit cancel first.
So you need to hit try out every single time and hit click on execute there.
Now this request goes to http localhost API V1 and slash AE.
So this is the part that is coming up.
Our message is also coming up nicely returns a greeting message from AE and we get a response body which
says hello from the AE docs.
We also see some of the response header.
Remember in the docs of Express, I mentioned that you can also set some headers via the back end.
This is exactly how you do this and this is how you get it.
Now in here we see that all good success.
These are response code that what is going to happen and how it works.
Since in the response code we have mentioned that the media type that is coming up is the application
JSON.
That's why it's coming up and all the basic schemas.
Now good thing is notice here in the example value there is a schema.
You can click on this and it will give you that exact schema that is coming up like string and example
is going to be a string.
So this actually gives the user an idea that what kind of response I'm going to get back.
Of course the user can actually execute, but writing a schema is always a good idea in case your application
is too much heavily driven on this entire thing.
Now coming up, back to the part, we will be working on it a little bit.
One more thing I would like to mention here.
You can see that we have this default AE So how you can change this default, this is the basic and
I know this is not too much visible here, but this is all grayed out.
So this is how you actually group all of the requests together.
So what you can do, you can actually tag these requests.
So just after the get request, I can go ahead and hit the tag.
So I'm going to say tags and let's go ahead and call this one as.
String.
Now you can get this tag onto multiple other paths as well.
And as soon as you are going to do this and let me hit a refresh and now notice a string.
So all the other requests that are related to this particular tag string, they will not go further
down in the road, but actually automatically will come up into this group, which is the string group.
I will also explain this a little bit more in depth later on, but I guess this is all it for now.
And let's go back into the next video.