Hey, did everyone had their share?
And welcome to another video.
So after really a long time, we'll be finally testing out our route.
I know in the last sections we have done it much more faster and in the future section we'll be also
doing it faster.
But this in-depth knowledge of why we are using everything and reading their documentation is really
must have.
Because I know most of you won't be reading it on your own, so I have to walk you through with the
reading of Doc's part.
Okay, so go ahead.
Fire up your postman.
And in this one, we are going to use Postman to handle the request.
So we have a route which is less registered, which is doing pretty significant job.
It's taking all the parameters first name, last name, email and password, and it's checking all of
them are required and then saving it to the database as well.
So pretty interesting stuff.
We want to see how that happens.
But we also don't want to use the postman just like as it is that we have done so far.
Now we want to use it a little bit more professionally.
What do I mean by that?
Now, this postman is a really important tool or any other tool that you are using now.
Most of the time, once you are done with all the back end information, you have to give this information
to the front end guy as well, whether React, Angular or mobile, whatever he's using now, definitely
writing the documentation helps to understand it much more, but these days, handling it through the
workspace of or the collection of a postman is kind of a very common.
It's notoriously known for one of the the standard of the industry tool for testing the APIs.
And this is really powerful one.
So go ahead.
Instead of just creating plus here and creating a new request, we won't be doing it.
We will be creating it via a new collection.
Let's call this one as ae auth app or TAP not eight.
It's a little bit smaller.
That's all the complaint that I have that no matter what I do, I try these things all cannot I can
cannot increase the size and all of that.
Okay, now this is all being done.
Now let's go ahead and first create an environment variable, just like you can create environment variable
onto the Hiroko and stuff you can create here as well.
But these are like little bit less than not that complex.
So we're going to go ahead and create an environment variable.
So this is a new environment.
We're going to call this one as auth app environment.
And here you can go ahead and add the variable.
So I'm going to go ahead and say this is my variable, I'm calling it as domain.
And the initial value and the current value, they are all going to be same.
So I'm going to go ahead and say http, colon, slash, slash, local host colon 4000.
So this is the port that I have to keep on writing again and again so I can go ahead and add that.
So let's go ahead and set this as available and set as a new variable.
And the name of the variable is domain.
So we're going to go ahead and call this one as domain.
You can also select the scope of it that this is an environment or a collection or this is a global.
So this is going to be a collection one.
So let's go ahead and go like that.
I don't need to select anything.
I just clicked off, click or that.
Okay, so this is all good.
Now what I can do is now it says no environment, but I can drop down and select the auth app.
Now all the variables that I've set it up here, they will become active automatically.
So what does this mean?
Actually, I can go ahead and save this and I can close all of this.
So this is how you'll be seeing now inside the collection, I'll go into the LCO Auth app, this is
where it is and make sure you have dropdown selected the correct environment in which you have set the
variable name and everything.
And now I can go ahead and make a request up here.
So let's go ahead and create a request in here.
So right click and we can actually say add a request.
There we go.
This request is for registered.
So I'm going to go ahead and say this one is for register.
Register route.
This one is going to be a post request.
And there we're going to go ahead and say, hey, I want to use a variable which is domain.
There we go at the end.
And now I can just simply say slash register.
So this is all the basics of it.
Now we can go ahead and hit that.
And just to give you a brief look and idea about it, we can go ahead and say instead of this, we can
actually hit the home route as well.
So let me go ahead and send this one and then we go, hello, from the old system.
So other variables are working nicely.
I'm going to go ahead and say go ahead and use register.
Okay.
I have to blur out a few screen because there might be some other work that I'm doing contract and they
might get exposed here as well.
Okay, now let's go ahead and send this one.
This should be giving us error because there is no get request.
So notice it says, hey, error cannot get because there is no get defined here.
Now inside the post, if I go ahead and hit the send, it says all field are required.
So that's awesome that our variables are now working in.
Now let's go into the body part.
Remember, you can go for authorization headers and all bunch will go for body, not the non part but
actually into the raw and also not the text but actually the JSON, not JavaScript.
This is a common error.
I've seen people struggling for hours and hour on this.
They haven't selected the proper JSON format.
So this is the JSON and we require all the fields.
So let's go ahead and provide them.
So this is going to be first name.
Let's go ahead and give the first name as one.
We have to provide last name that is going to be AE and then we have to provide email and that email
is going to be.
One at AE dev.
And finally, we have to pass on the password and that password is going to be let's go ahead and say
one, two, three, four, five, six.
Now, since this is a JSON, all the keys should be wrapped up inside the codes and the value should
also be wrapped up inside the code until unless it's a numerical value.
Let's go ahead and send this one and notice here it gives me back my whatever the user that I've created
that's entirely in the user variable.
So first name, let me expand that.
So I get the first name, last name, email, password ID notice I told you underscore ID, that's exactly
the ID.
We are getting the token as well.
Now our password is getting encrypted.
But why?
To send even the encrypted password to anybody?
That is the problem that we are facing now.
There are a couple of ways how we can handle the password situation.
One way actually goes directly into the model and say, Hey, whenever I just call you an object or
you return me back by default, please don't return me the password.
There is a way to say that and we can omit any field via the model itself.
But in case you haven't done that, then you can go ahead, come back here into the app or wherever
you have written the root just below that to do.
You can go ahead and say up here that, hey, I want to say user dot password and you can go ahead and
set it to undefined.
Now it will not set it undefined into the database itself because remember we are not saving anything.
We have got this as undefined, whatever, you have saved it, you have given me back that user in that
one properties I'm setting is at undefined and if any property set is undefined, it doesn't show up
again.
Let's go ahead and try that one more time.
So I'm going to go ahead and register another user and let's it's a good time to check whether this
user exists or not.
Let's go ahead and send it again.
It says user already exists.
So that is also working nicely.
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.
So let's go ahead and send this one again.
And this time we are not receiving the password.
So that was that to do that, I wanted to show you that, yeah, this is the kind of issue that we are
facing right now.
But since now we have handled that, I can actually go ahead and remove this part because we have handled
that now.
Also, I would like to show you one more thing inside the database.
Let me go ahead and refresh that.
So now we have a new database which is auth AE.
It is having two users.
I can go ahead and open this up and I can see that all the information that is coming in.
So I have this underscore ID.
Yeah, weird stuff user dot underscore id if we have user dot, first name, last name, email, password,
encrypted and everything and versions and everything are being stored.
Okay, this is really nice and interesting.
And do you want to store this token into your database or not?
That's totally 100% up to you.
You can just move this token generation part at the top and later on you can save that.
I haven't seen much people saving this into the database itself because it's not often much use in saving
that.
But again, there are a lot of strategies and everybody believes that their strategy is the best one.
Go ahead and explore your own strategy.
Okay.
Quite a lot of stuff that we have done today.
Let's go ahead and catch up tomorrow for you just next video.