WEBVTT

00:03.980 --> 00:05.900
Moving up on to the final note.

00:05.930 --> 00:06.350
Hey there.

00:06.350 --> 00:07.490
Everyone had their share.

00:07.490 --> 00:09.080
And I know you are enjoying the series.

00:09.080 --> 00:11.570
If you are enjoying this series, let me know on Instagram.

00:11.570 --> 00:13.300
It actually boost my morals.

00:13.310 --> 00:14.950
So let's go up here.

00:14.960 --> 00:21.200
The final thing we have all taken care about, these four roots, the home page, greetings, the Instagram,

00:21.200 --> 00:22.520
Facebook and LinkedIn.

00:22.520 --> 00:25.610
And now it's time to take care of this root, which is a little bit tricky.

00:25.610 --> 00:31.670
We have slash API slash let's go for V one also here and then we have slash four.

00:31.670 --> 00:33.590
So we have to return four in this case.

00:33.590 --> 00:38.450
But it can be my name or it can be something like a token.

00:38.630 --> 00:42.530
Whatever the user says, we have to actually go ahead and return that back.

00:42.830 --> 00:43.110
Okay.

00:43.250 --> 00:48.740
So if you'll do a little bit of the research, this anything that comes up into the URL, this has a

00:48.740 --> 00:49.850
lot of name.

00:49.850 --> 00:54.860
And what you're going to notice if I just show you up here in the comment section at the very bottom,

00:54.860 --> 01:00.050
there you are actually look something like this which is HTTPS call and slash laughs, let's just say

01:00.080 --> 01:05.780
ae dot dev and sometimes there are some routes, something like token or something.

01:05.990 --> 01:12.140
But you're also going to notice that sometimes it says something like question mark and then say price

01:12.140 --> 01:14.420
equals 23, something like that.

01:14.420 --> 01:17.480
And there is a specific name for each one of these things.

01:17.480 --> 01:21.710
This one here is known as root or sometimes as parameters.

01:21.710 --> 01:27.140
This one is known as query because it's being a question mark is there and after that.

01:27.140 --> 01:30.950
So we need to understand this URL in depth and we will be doing that later on.

01:30.950 --> 01:36.590
But right now, all we need to know as of now that what we're talking about here is, is parameters.

01:36.590 --> 01:41.900
So how we can return the exact parameter that is given to me in the URL back to the user.

01:41.900 --> 01:42.680
I don't know that.

01:42.680 --> 01:45.080
So we will take help from the documentation.

01:45.080 --> 01:47.030
Now of course we need to first grab it.

01:47.030 --> 01:51.770
So I should look into the request that how I can actually grab this one and I can see there are a lot

01:51.770 --> 01:52.460
of methods here.

01:52.460 --> 01:57.470
For example, there is a request path, so I can say, okay, there is a path, but I can grab the path

01:57.470 --> 01:59.000
by saying request dot path.

01:59.000 --> 02:05.450
When I say this one and a whole lot of this one comes up, I'm able to grab this slash user that can

02:05.450 --> 02:05.870
be good.

02:05.870 --> 02:11.300
One of the viable options that I can remove by JavaScript this slash and return back this that's one

02:11.300 --> 02:11.870
option.

02:11.870 --> 02:15.020
But if you look a little bit here, there's a request or query.

02:15.110 --> 02:18.230
And when you get this query, what you get is this one.

02:18.230 --> 02:23.390
So if anybody asks you for the query, you get all the things which are after the question mark.

02:23.390 --> 02:27.800
What we are looking for here is actually request dot params.

02:27.830 --> 02:34.100
Now notice here it says when somebody says get slash user slash TJ, this is exactly what you get the

02:34.100 --> 02:36.830
TJ part and this is exactly I'm looking for.

02:36.830 --> 02:41.300
Definitely there is a lot more that you can do, but this is exactly going to solve our issue.

02:41.300 --> 02:47.630
So request is a big gigantic object which has this params and we are going to go ahead and grab this

02:47.630 --> 02:48.080
one.

02:48.320 --> 02:48.570
Okay.

02:48.680 --> 02:49.940
Let's go ahead and give it a try.

02:49.970 --> 02:50.930
Maybe we'll succeed.

02:50.930 --> 02:51.680
Maybe we'll not.

02:51.680 --> 02:53.720
So notice here very carefully.

02:53.720 --> 02:57.260
I'm going at the very top just below the slash.

02:57.260 --> 03:03.830
I'm trying to write my code here app dot get of course and then I'm going to go ahead that whenever

03:03.830 --> 03:11.330
somebody hits the root so I'm going to say this is a slash and notice this is slash API, slash V1 and

03:11.330 --> 03:14.480
then how I'm going to define that, what's coming up into the root.

03:14.480 --> 03:20.840
So notice here, if I go back up here, this says, okay, anybody can hit the slash user, slash TJ

03:20.840 --> 03:22.670
and you'll get the TJ up here.

03:23.660 --> 03:24.680
That's great.

03:24.680 --> 03:28.700
But there's a little bit more confusion that's coming up that how am I going to define that?

03:28.700 --> 03:33.140
So in this case, we have to actually go ahead and see a little bit more of that.

03:33.140 --> 03:34.610
So let me walk you through with that.

03:34.730 --> 03:39.950
Now, if you want to grab any of the parameters from this, what you need to say is like this, and

03:39.950 --> 03:44.000
then you can simply say colon and then feel free to name it whatever you like.

03:44.000 --> 03:48.110
You can call this ID, you can call this one as token, whatever you wish.

03:48.110 --> 03:50.330
And there are a couple of more ways how we can grab that.

03:50.480 --> 03:52.550
I'll show you all of them here in this video.

03:52.550 --> 03:53.360
Don't do worry.

03:53.480 --> 03:53.980
Okay.

03:54.380 --> 03:58.730
Now, notice here, I've put up a colon here that is very important in this case and we'll work on that.

03:58.730 --> 04:00.920
This is actual parameters, how we do that.

04:00.920 --> 04:04.070
And then we simply go ahead and say request and response.

04:04.850 --> 04:06.110
And just like this.

04:06.110 --> 04:11.090
Now, first thing that I would like to do here is that let's console.log this.

04:11.090 --> 04:14.420
So we're going to simply say log and oops.

04:15.630 --> 04:16.770
Console.log.

04:16.920 --> 04:24.720
And I'm going to say that hey, request dot params and then dot token the notice here I'm calling it

04:24.720 --> 04:26.820
as token because I've mentioned it as token here.

04:26.820 --> 04:33.340
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.

04:33.340 --> 04:40.500
So I'm going to simply say rez as a response dot send or probably I want to just raise a status first.

04:40.500 --> 04:45.600
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

04:45.600 --> 04:47.570
to get a JSON data back.

04:47.580 --> 04:52.680
So in the JSON, I'm going to go ahead and say that I, I will say that as parameter.

04:52.690 --> 04:54.390
So I'm going to simply say param.

04:54.540 --> 05:00.300
And then in the param, after that, I'm going to go ahead and I haven't stored this entire value into,

05:01.020 --> 05:02.280
into available.

05:02.280 --> 05:06.870
So I don't need to I can just go ahead and come up here and say request dot params dot token.

05:06.870 --> 05:08.460
You can store that in a variable too.

05:08.610 --> 05:13.140
Now let's go ahead and save this one and let's see how many mistakes we have made.

05:13.290 --> 05:15.720
So let's go ahead and call this one up here.

05:15.720 --> 05:19.560
And by the way, I've turned my this post went into dark mode.

05:19.560 --> 05:21.600
Now I absolutely forgot that.

05:21.600 --> 05:26.490
Now let's go ahead and say if somebody sends me a three back, let's see what happens.

05:26.490 --> 05:27.240
If I go back.

05:27.240 --> 05:29.310
It says params three.

05:29.610 --> 05:31.080
Okay, that's fine.

05:31.320 --> 05:36.710
And if I go ahead and say my name it says param headache oc.

05:36.720 --> 05:37.590
That is fine.

05:37.590 --> 05:40.140
But what about if I don't put up anything?

05:40.140 --> 05:42.150
What's going to happen in that case?

05:42.720 --> 05:46.860
Let's go ahead and save this one and see what the URL is actually saying.

05:46.860 --> 05:51.930
It's saying, hey, you're going to request a request dot params name and then you get the TJ.

05:52.260 --> 05:56.460
So where this name is actually coming up from, there is no information given up here.

05:56.460 --> 05:58.110
Let's go ahead and give it a try.

05:58.230 --> 06:05.010
So we're going to go ahead and say request dot params dot name going with that and let's go ahead and

06:05.010 --> 06:10.890
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

06:10.890 --> 06:11.460
errors.

06:11.460 --> 06:17.100
So yes, analyzing the documentation sometimes can be tricky and sometimes you need a little bit more

06:17.100 --> 06:17.940
information.

06:17.970 --> 06:20.550
Yes, that is also possible to grab that.

06:20.550 --> 06:26.160
But in case what's what's going to solve our purpose is actually the special name here.

06:26.160 --> 06:31.770
So whenever you need to accept any value in the URL, the colon is your friend and after the colon you

06:31.770 --> 06:33.240
can just name it anything.

06:33.240 --> 06:38.190
In case you want to take more parameters, you can just go ahead and say slash and then you can provide

06:38.190 --> 06:43.860
a colon and then can say ID and that parameter will be available to request params ID.

06:43.860 --> 06:49.770
So you have requested params dot token whatever you call that in the URL that you need to accept here

06:49.770 --> 06:50.370
as well.

06:50.400 --> 06:52.470
You get the idea how this is being done.

06:52.470 --> 06:57.750
So yes, I'm trying to say that analyzing the documentation sometimes requires a little bit more study

06:57.750 --> 06:59.850
and probably sometimes help from seniors.

07:00.060 --> 07:01.860
Okay, this is all good.

07:01.860 --> 07:05.310
I'm super happy, but we have actually broke our application.

07:05.310 --> 07:08.790
Let me show you why our Instagram link was working fine.

07:08.790 --> 07:13.260
So I'm going to go ahead and say Instagram and now it says, hey, perhaps it's Instagram.

07:13.380 --> 07:18.480
So, yes, this exactly happens in the backend development that you have built something and you have

07:18.480 --> 07:19.380
broke something.

07:19.380 --> 07:23.880
Previously these all four were working absolutely fine and this was not there.

07:23.880 --> 07:27.000
But now you have introduced it and this has broken it all.

07:27.000 --> 07:30.120
Now, probably, probably these all things are in a separate file.

07:30.120 --> 07:31.830
These are routes, these all methods.

07:31.830 --> 07:34.770
And imagine how many places you have to debug the application.

07:35.160 --> 07:37.290
In this case, the error is pretty obvious.

07:37.290 --> 07:43.930
The reason why it is pretty obvious is because the way how these roots are defined, they actually governs

07:43.950 --> 07:45.300
what is going to happen.

07:45.300 --> 07:51.720
So if I go ahead and simply cut this out and I place it at the very bottom of it just before the app

07:51.720 --> 07:56.490
is listening, now what's going to happen is it's going to try to match with all these routes.

07:56.490 --> 07:57.870
So first it's going to try to match.

07:57.870 --> 07:58.740
Is it Instagram?

07:58.740 --> 07:59.130
No.

07:59.130 --> 08:00.090
Is it Facebook?

08:00.090 --> 08:00.630
No.

08:00.660 --> 08:01.500
Is it LinkedIn?

08:01.500 --> 08:01.830
No.

08:01.830 --> 08:05.610
And then any other will get into these routes and we'll get the data.

08:05.610 --> 08:09.900
So if I go back onto this application, I go ahead and send this one.

08:09.900 --> 08:15.300
Now I get the Instagram data, but as soon as I add anything like Instagram's, I go ahead and return

08:15.300 --> 08:16.050
that parameter.

08:16.050 --> 08:19.020
So a pretty classic application that we have built up here.

08:20.310 --> 08:22.800
Is this all fine as an application?

08:22.800 --> 08:26.460
No, there are a couple of more bugs, but we are not going to see them yet.

08:26.460 --> 08:28.980
We're going to see them in the production.

08:28.980 --> 08:29.370
Yes.

08:29.370 --> 08:30.930
That's where we are going to play next.

08:30.930 --> 08:34.860
So we have all things all geared up and this is all what we got up here.

08:34.860 --> 08:40.440
Now, at this moment, I would say your application is fully ready, at least from your side.

08:40.440 --> 08:44.280
And let's close this one up here so your application from your end is all ready.

08:44.280 --> 08:48.720
Now, only thing that's remaining is to deploy this application, and obviously we are going to catch

08:48.720 --> 08:49.890
that up in the next video.

08:49.920 --> 08:55.740
Let's fire up our Heroku and see that how we can push this application into production, make sure the

08:55.740 --> 08:59.910
hero quickly is installed in your system and I'm going to catch you up in the next video.
