Moving up on to the final note.
Hey there.
Everyone had their share.
And I know you are enjoying the series.
If you are enjoying this series, let me know on Instagram.
It actually boost my morals.
So let's go up here.
The final thing we have all taken care about, these four roots, the home page, greetings, the Instagram,
Facebook and LinkedIn.
And now it's time to take care of this root, which is a little bit tricky.
We have slash API slash let's go for V one also here and then we have slash four.
So we have to return four in this case.
But it can be my name or it can be something like a token.
Whatever the user says, we have to actually go ahead and return that back.
Okay.
So if you'll do a little bit of the research, this anything that comes up into the URL, this has a
lot of name.
And what you're going to notice if I just show you up here in the comment section at the very bottom,
there you are actually look something like this which is HTTPS call and slash laughs, let's just say
ae dot dev and sometimes there are some routes, something like token or something.
But you're also going to notice that sometimes it says something like question mark and then say price
equals 23, something like that.
And there is a specific name for each one of these things.
This one here is known as root or sometimes as parameters.
This one is known as query because it's being a question mark is there and after that.
So we need to understand this URL in depth and we will be doing that later on.
But right now, all we need to know as of now that what we're talking about here is, is parameters.
So how we can return the exact parameter that is given to me in the URL back to the user.
I don't know that.
So we will take help from the documentation.
Now of course we need to first grab it.
So I should look into the request that how I can actually grab this one and I can see there are a lot
of methods here.
For example, there is a request path, so I can say, okay, there is a path, but I can grab the path
by saying request dot path.
When I say this one and a whole lot of this one comes up, I'm able to grab this slash user that can
be good.
One of the viable options that I can remove by JavaScript this slash and return back this that's one
option.
But if you look a little bit here, there's a request or query.
And when you get this query, what you get is this one.
So if anybody asks you for the query, you get all the things which are after the question mark.
What we are looking for here is actually request dot params.
Now notice here it says when somebody says get slash user slash TJ, this is exactly what you get the
TJ part and this is exactly I'm looking for.
Definitely there is a lot more that you can do, but this is exactly going to solve our issue.
So request is a big gigantic object which has this params and we are going to go ahead and grab this
one.
Okay.
Let's go ahead and give it a try.
Maybe we'll succeed.
Maybe we'll not.
So notice here very carefully.
I'm going at the very top just below the slash.
I'm trying to write my code here app dot get of course and then I'm going to go ahead that whenever
somebody hits the root so I'm going to say this is a slash and notice this is slash API, slash V1 and
then how I'm going to define that, what's coming up into the root.
So notice here, if I go back up here, this says, okay, anybody can hit the slash user, slash TJ
and you'll get the TJ up here.
That's great.
But there's a little bit more confusion that's coming up that how am I going to define that?
So in this case, we have to actually go ahead and see a little bit more of that.
So let me walk you through with that.
Now, if you want to grab any of the parameters from this, what you need to say is like this, and
then you can simply say colon and then feel free to name it whatever you like.
You can call this ID, you can call this one as token, whatever you wish.
And there are a couple of more ways how we can grab that.
I'll show you all of them here in this video.
Don't do worry.
Okay.
Now, notice here, I've put up a colon here that is very important in this case and we'll work on that.
This is actual parameters, how we do that.
And then we simply go ahead and say request and response.
And just like this.
Now, first thing that I would like to do here is that let's console.log this.
So we're going to simply say log and oops.
Console.log.
And I'm going to say that hey, request dot params and then dot token the notice here I'm calling it
as token because I've mentioned it as token here.
If I would be calling it as ID, I would be mentioning it as ID and I want to send that back as a response.
So I'm going to simply say rez as a response dot send or probably I want to just raise a status first.
So I'm going to go ahead and say 200 and then you can send a dot send or in this case, I would love
to get a JSON data back.
So in the JSON, I'm going to go ahead and say that I, I will say that as parameter.
So I'm going to simply say param.
And then in the param, after that, I'm going to go ahead and I haven't stored this entire value into,
into available.
So I don't need to I can just go ahead and come up here and say request dot params dot token.
You can store that in a variable too.
Now let's go ahead and save this one and let's see how many mistakes we have made.
So let's go ahead and call this one up here.
And by the way, I've turned my this post went into dark mode.
Now I absolutely forgot that.
Now let's go ahead and say if somebody sends me a three back, let's see what happens.
If I go back.
It says params three.
Okay, that's fine.
And if I go ahead and say my name it says param headache oc.
That is fine.
But what about if I don't put up anything?
What's going to happen in that case?
Let's go ahead and save this one and see what the URL is actually saying.
It's saying, hey, you're going to request a request dot params name and then you get the TJ.
So where this name is actually coming up from, there is no information given up here.
Let's go ahead and give it a try.
So we're going to go ahead and say request dot params dot name going with that and let's go ahead and
save this one and let's go back up here and I send this one and notice here this time we get a lot of
errors.
So yes, analyzing the documentation sometimes can be tricky and sometimes you need a little bit more
information.
Yes, that is also possible to grab that.
But in case what's what's going to solve our purpose is actually the special name here.
So whenever you need to accept any value in the URL, the colon is your friend and after the colon you
can just name it anything.
In case you want to take more parameters, you can just go ahead and say slash and then you can provide
a colon and then can say ID and that parameter will be available to request params ID.
So you have requested params dot token whatever you call that in the URL that you need to accept here
as well.
You get the idea how this is being done.
So yes, I'm trying to say that analyzing the documentation sometimes requires a little bit more study
and probably sometimes help from seniors.
Okay, this is all good.
I'm super happy, but we have actually broke our application.
Let me show you why our Instagram link was working fine.
So I'm going to go ahead and say Instagram and now it says, hey, perhaps it's Instagram.
So, yes, this exactly happens in the backend development that you have built something and you have
broke something.
Previously these all four were working absolutely fine and this was not there.
But now you have introduced it and this has broken it all.
Now, probably, probably these all things are in a separate file.
These are routes, these all methods.
And imagine how many places you have to debug the application.
In this case, the error is pretty obvious.
The reason why it is pretty obvious is because the way how these roots are defined, they actually governs
what is going to happen.
So if I go ahead and simply cut this out and I place it at the very bottom of it just before the app
is listening, now what's going to happen is it's going to try to match with all these routes.
So first it's going to try to match.
Is it Instagram?
No.
Is it Facebook?
No.
Is it LinkedIn?
No.
And then any other will get into these routes and we'll get the data.
So if I go back onto this application, I go ahead and send this one.
Now I get the Instagram data, but as soon as I add anything like Instagram's, I go ahead and return
that parameter.
So a pretty classic application that we have built up here.
Is this all fine as an application?
No, there are a couple of more bugs, but we are not going to see them yet.
We're going to see them in the production.
Yes.
That's where we are going to play next.
So we have all things all geared up and this is all what we got up here.
Now, at this moment, I would say your application is fully ready, at least from your side.
And let's close this one up here so your application from your end is all ready.
Now, only thing that's remaining is to deploy this application, and obviously we are going to catch
that up in the next video.
Let's fire up our Heroku and see that how we can push this application into production, make sure the
hero quickly is installed in your system and I'm going to catch you up in the next video.