- [Instructor] What if you need
to retrieve just the information of a specific contact?
This is when a specific ID endpoint comes into play.
So let's get to it.
So the first thing you need to do is have, again,
the CRM controller file open.
And what we're going to do is copy and paste
what we have from line 17 to line 24,
and paste it, again, here.
And what we're going to do is call this one
get contact with ID.
Request response is the same.
What we need to change here for the method
that we're using in the database is find by ID
as opposed to just find.
Find by ID, like so.
And then we need to pass some parameters.
So what we need to do is remove the curly braces,
and then we need to pass a parameters.
So just as information, when you get the request object,
you have a whole bunch of information with it.
You have the body, which has the data.
So if we go back to Postman,
when you make a request, you're going to have
in the request dot body, the information
that you have in here.
But you also have a whole bunch of other things
that you have access to.
And one of them is params.
So let's go ahead and do request dot params dot contact ID.
And the contact ID needs to reflect exactly
what you have in the routes here.
If it doesn't, then you're not going to pass the information
that is in here.
So contact ID needs to be exactly the same as this.
So it is, so we're good.
And a good way to understand what's coming
with the request is to take a look
at a tool inside of Postman,
and I'll show you in a second
how you can work with that tool.
So let's finish our code here first,
and then I'll show you in Postman
how we make first the request,
and then what information you have.
So everything else is pretty much the same.
We're doing error contact.
If error, send error, and if you have some information,
get a response through a json object.
All right, so that is for the function.
So now we need to, again, pass it in the CRM routes.
So what you need to do first is import it,
like everything else we've done so far.
So we're going to go back here, and then do comma,
and then go to get contact with ID.
And then pass this into a new method
that we're going to pass inside this route here.
So what we're going to do is insert a brand-new method
that we're going to call the get for a specific contact.
Because we can't use the get here,
because the actual URL doesn't pass a specific ID.
We're passing a specific ID in this URL here,
so we need to create the method in this particular wrap.
And then we're going to pass the function
that we just imported.
So that completes the portion of the code,
so let's go into Postman and take a look
at how we can test this.
But before, let me introduce the tool
that I referred to earlier.
So this tool is this guy here.
It's called the Postman console.
So if you open it, whenever you make a request,
you're going to be able to see everything
that you sent to the API.
So let's go ahead and turn it on.
So we're going to click on this, and it's going
to open a brand new page.
And when we make a request, we're going to see
what is the request and what was in that request.
So let's go ahead and make one.
And this one, we need to do a get with a specific ID.
So we need to be specific as to which ID we're getting.
So let's go and grab the ID of this one here.
Let's copy that.
And let's do forward slash and pass the ID.
And then we don't need to send any form for this one,
so it's just a get of that specific ID.
Now let's go ahead and send the request.
So we're going to send the request,
and then we're going to get the specific ID
that we requested.
And what you also want to take a look at is the console
that we just opened.
And if you click on the get request that we just sent,
you see everything that we sent to the server.
So the request headers, the response headers,
and then the response body.
If we add anything in the request body,
so if we sent something to post,
and let's just send one just for kicks.
So let's go and do a post.
Let's use a URL, and for this one, let's do Jasmine.
And let's do the post.
We got a response back.
Let's go back to our console.
And we've got a brand new request.
And now you have a request body.
And now you can see the information
that you sent to the server.
So when you're doing request,
the request object is basically this request object.
When you get the response, this is the response object.
So this is what you get back from the server.
So now, if you need any specific contact and their data,
you can pull only a specific contact by its ID.
We're almost there.
We're completing our endpoint, so let's move on
to building the rest.