WEBVTT

00:03.850 --> 00:05.530
Hey, did everyone had their share?

00:05.530 --> 00:06.950
And welcome to another video.

00:06.970 --> 00:11.290
So after really a long time, we'll be finally testing out our route.

00:11.410 --> 00:16.060
I know in the last sections we have done it much more faster and in the future section we'll be also

00:16.060 --> 00:16.810
doing it faster.

00:16.810 --> 00:21.940
But this in-depth knowledge of why we are using everything and reading their documentation is really

00:21.940 --> 00:22.720
must have.

00:22.720 --> 00:26.830
Because I know most of you won't be reading it on your own, so I have to walk you through with the

00:26.830 --> 00:28.090
reading of Doc's part.

00:28.330 --> 00:29.230
Okay, so go ahead.

00:29.230 --> 00:30.250
Fire up your postman.

00:30.250 --> 00:33.100
And in this one, we are going to use Postman to handle the request.

00:33.100 --> 00:36.880
So we have a route which is less registered, which is doing pretty significant job.

00:36.880 --> 00:41.740
It's taking all the parameters first name, last name, email and password, and it's checking all of

00:41.740 --> 00:44.590
them are required and then saving it to the database as well.

00:44.590 --> 00:45.670
So pretty interesting stuff.

00:45.670 --> 00:47.260
We want to see how that happens.

00:47.260 --> 00:51.610
But we also don't want to use the postman just like as it is that we have done so far.

00:51.640 --> 00:54.280
Now we want to use it a little bit more professionally.

00:54.280 --> 00:55.660
What do I mean by that?

00:55.660 --> 00:59.380
Now, this postman is a really important tool or any other tool that you are using now.

00:59.380 --> 01:03.760
Most of the time, once you are done with all the back end information, you have to give this information

01:03.760 --> 01:08.740
to the front end guy as well, whether React, Angular or mobile, whatever he's using now, definitely

01:08.740 --> 01:13.180
writing the documentation helps to understand it much more, but these days, handling it through the

01:13.180 --> 01:17.440
workspace of or the collection of a postman is kind of a very common.

01:17.440 --> 01:23.110
It's notoriously known for one of the the standard of the industry tool for testing the APIs.

01:23.110 --> 01:25.150
And this is really powerful one.

01:25.150 --> 01:25.870
So go ahead.

01:25.870 --> 01:29.230
Instead of just creating plus here and creating a new request, we won't be doing it.

01:29.230 --> 01:32.020
We will be creating it via a new collection.

01:32.020 --> 01:36.400
Let's call this one as ae auth app or TAP not eight.

01:37.150 --> 01:38.260
It's a little bit smaller.

01:38.260 --> 01:44.050
That's all the complaint that I have that no matter what I do, I try these things all cannot I can

01:44.230 --> 01:46.270
cannot increase the size and all of that.

01:46.450 --> 01:47.950
Okay, now this is all being done.

01:47.950 --> 01:53.080
Now let's go ahead and first create an environment variable, just like you can create environment variable

01:53.080 --> 01:55.540
onto the Hiroko and stuff you can create here as well.

01:55.540 --> 01:58.690
But these are like little bit less than not that complex.

01:58.690 --> 02:01.030
So we're going to go ahead and create an environment variable.

02:01.030 --> 02:02.500
So this is a new environment.

02:02.620 --> 02:06.310
We're going to call this one as auth app environment.

02:06.760 --> 02:09.280
And here you can go ahead and add the variable.

02:09.280 --> 02:12.700
So I'm going to go ahead and say this is my variable, I'm calling it as domain.

02:12.850 --> 02:16.330
And the initial value and the current value, they are all going to be same.

02:16.330 --> 02:23.290
So I'm going to go ahead and say http, colon, slash, slash, local host colon 4000.

02:23.290 --> 02:27.490
So this is the port that I have to keep on writing again and again so I can go ahead and add that.

02:27.490 --> 02:32.680
So let's go ahead and set this as available and set as a new variable.

02:33.520 --> 02:36.670
And the name of the variable is domain.

02:36.880 --> 02:39.220
So we're going to go ahead and call this one as domain.

02:39.520 --> 02:44.050
You can also select the scope of it that this is an environment or a collection or this is a global.

02:44.050 --> 02:46.270
So this is going to be a collection one.

02:46.510 --> 02:49.550
So let's go ahead and go like that.

02:49.570 --> 02:50.620
I don't need to select anything.

02:50.620 --> 02:52.450
I just clicked off, click or that.

02:52.670 --> 02:54.100
Okay, so this is all good.

02:54.130 --> 02:59.420
Now what I can do is now it says no environment, but I can drop down and select the auth app.

02:59.440 --> 03:03.390
Now all the variables that I've set it up here, they will become active automatically.

03:03.400 --> 03:04.420
So what does this mean?

03:04.420 --> 03:07.590
Actually, I can go ahead and save this and I can close all of this.

03:07.600 --> 03:13.090
So this is how you'll be seeing now inside the collection, I'll go into the LCO Auth app, this is

03:13.090 --> 03:17.860
where it is and make sure you have dropdown selected the correct environment in which you have set the

03:17.860 --> 03:19.180
variable name and everything.

03:19.180 --> 03:21.940
And now I can go ahead and make a request up here.

03:21.940 --> 03:24.070
So let's go ahead and create a request in here.

03:24.130 --> 03:27.670
So right click and we can actually say add a request.

03:27.880 --> 03:28.670
There we go.

03:28.690 --> 03:30.750
This request is for registered.

03:30.910 --> 03:33.730
So I'm going to go ahead and say this one is for register.

03:35.330 --> 03:36.560
Register route.

03:36.680 --> 03:39.500
This one is going to be a post request.

03:39.770 --> 03:45.580
And there we're going to go ahead and say, hey, I want to use a variable which is domain.

03:45.590 --> 03:46.910
There we go at the end.

03:47.360 --> 03:51.290
And now I can just simply say slash register.

03:52.820 --> 03:54.200
So this is all the basics of it.

03:54.200 --> 03:55.550
Now we can go ahead and hit that.

03:55.550 --> 04:00.050
And just to give you a brief look and idea about it, we can go ahead and say instead of this, we can

04:00.050 --> 04:01.610
actually hit the home route as well.

04:01.610 --> 04:05.930
So let me go ahead and send this one and then we go, hello, from the old system.

04:05.930 --> 04:08.240
So other variables are working nicely.

04:08.240 --> 04:12.290
I'm going to go ahead and say go ahead and use register.

04:12.920 --> 04:13.150
Okay.

04:13.160 --> 04:18.470
I have to blur out a few screen because there might be some other work that I'm doing contract and they

04:18.470 --> 04:20.000
might get exposed here as well.

04:20.150 --> 04:21.980
Okay, now let's go ahead and send this one.

04:21.980 --> 04:24.950
This should be giving us error because there is no get request.

04:24.950 --> 04:28.880
So notice it says, hey, error cannot get because there is no get defined here.

04:28.880 --> 04:33.620
Now inside the post, if I go ahead and hit the send, it says all field are required.

04:33.620 --> 04:36.530
So that's awesome that our variables are now working in.

04:36.530 --> 04:38.150
Now let's go into the body part.

04:38.150 --> 04:43.730
Remember, you can go for authorization headers and all bunch will go for body, not the non part but

04:43.730 --> 04:49.490
actually into the raw and also not the text but actually the JSON, not JavaScript.

04:49.490 --> 04:50.600
This is a common error.

04:50.600 --> 04:53.030
I've seen people struggling for hours and hour on this.

04:53.030 --> 04:55.280
They haven't selected the proper JSON format.

04:55.520 --> 04:58.820
So this is the JSON and we require all the fields.

04:58.820 --> 05:00.140
So let's go ahead and provide them.

05:00.140 --> 05:02.150
So this is going to be first name.

05:02.510 --> 05:05.240
Let's go ahead and give the first name as one.

05:06.790 --> 05:17.710
We have to provide last name that is going to be AE and then we have to provide email and that email

05:17.710 --> 05:19.030
is going to be.

05:19.980 --> 05:22.380
One at AE dev.

05:22.950 --> 05:29.790
And finally, we have to pass on the password and that password is going to be let's go ahead and say

05:29.790 --> 05:31.090
one, two, three, four, five, six.

05:31.110 --> 05:35.370
Now, since this is a JSON, all the keys should be wrapped up inside the codes and the value should

05:35.370 --> 05:38.940
also be wrapped up inside the code until unless it's a numerical value.

05:38.970 --> 05:44.940
Let's go ahead and send this one and notice here it gives me back my whatever the user that I've created

05:44.940 --> 05:46.770
that's entirely in the user variable.

05:46.770 --> 05:48.930
So first name, let me expand that.

05:49.050 --> 05:55.380
So I get the first name, last name, email, password ID notice I told you underscore ID, that's exactly

05:55.380 --> 05:55.920
the ID.

05:55.950 --> 05:57.720
We are getting the token as well.

05:57.750 --> 05:59.640
Now our password is getting encrypted.

05:59.640 --> 06:00.570
But why?

06:00.600 --> 06:03.090
To send even the encrypted password to anybody?

06:03.090 --> 06:05.280
That is the problem that we are facing now.

06:05.280 --> 06:07.950
There are a couple of ways how we can handle the password situation.

06:07.950 --> 06:12.630
One way actually goes directly into the model and say, Hey, whenever I just call you an object or

06:12.630 --> 06:15.930
you return me back by default, please don't return me the password.

06:15.930 --> 06:19.950
There is a way to say that and we can omit any field via the model itself.

06:19.950 --> 06:27.120
But in case you haven't done that, then you can go ahead, come back here into the app or wherever

06:27.120 --> 06:29.460
you have written the root just below that to do.

06:29.490 --> 06:35.970
You can go ahead and say up here that, hey, I want to say user dot password and you can go ahead and

06:35.970 --> 06:37.470
set it to undefined.

06:37.500 --> 06:42.510
Now it will not set it undefined into the database itself because remember we are not saving anything.

06:42.930 --> 06:48.030
We have got this as undefined, whatever, you have saved it, you have given me back that user in that

06:48.030 --> 06:53.160
one properties I'm setting is at undefined and if any property set is undefined, it doesn't show up

06:53.160 --> 06:53.520
again.

06:53.520 --> 06:55.320
Let's go ahead and try that one more time.

06:55.320 --> 06:59.640
So I'm going to go ahead and register another user and let's it's a good time to check whether this

06:59.640 --> 07:00.600
user exists or not.

07:00.600 --> 07:02.010
Let's go ahead and send it again.

07:02.010 --> 07:03.450
It says user already exists.

07:03.450 --> 07:05.160
So that is also working nicely.

07:05.160 --> 07:11.910
So we're going to go ahead and say this time this is going to be two and this one is going to be two.

07:13.530 --> 07:15.750
So let's go ahead and send this one again.

07:15.870 --> 07:18.090
And this time we are not receiving the password.

07:18.090 --> 07:22.110
So that was that to do that, I wanted to show you that, yeah, this is the kind of issue that we are

07:22.110 --> 07:23.040
facing right now.

07:23.040 --> 07:28.140
But since now we have handled that, I can actually go ahead and remove this part because we have handled

07:28.140 --> 07:29.220
that now.

07:29.220 --> 07:31.980
Also, I would like to show you one more thing inside the database.

07:31.980 --> 07:33.600
Let me go ahead and refresh that.

07:33.600 --> 07:36.570
So now we have a new database which is auth AE.

07:36.600 --> 07:37.770
It is having two users.

07:37.770 --> 07:41.850
I can go ahead and open this up and I can see that all the information that is coming in.

07:41.850 --> 07:43.680
So I have this underscore ID.

07:43.710 --> 07:49.350
Yeah, weird stuff user dot underscore id if we have user dot, first name, last name, email, password,

07:49.350 --> 07:52.230
encrypted and everything and versions and everything are being stored.

07:52.560 --> 07:54.540
Okay, this is really nice and interesting.

07:54.540 --> 07:58.290
And do you want to store this token into your database or not?

07:58.290 --> 08:00.690
That's totally 100% up to you.

08:00.690 --> 08:04.770
You can just move this token generation part at the top and later on you can save that.

08:04.770 --> 08:10.800
I haven't seen much people saving this into the database itself because it's not often much use in saving

08:10.800 --> 08:10.950
that.

08:10.950 --> 08:14.930
But again, there are a lot of strategies and everybody believes that their strategy is the best one.

08:14.940 --> 08:17.130
Go ahead and explore your own strategy.

08:17.280 --> 08:17.610
Okay.

08:17.610 --> 08:19.230
Quite a lot of stuff that we have done today.

08:19.230 --> 08:22.440
Let's go ahead and catch up tomorrow for you just next video.
