From the course: MERN Essential Training
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Create specific ID GET endpoint
From the course: MERN Essential Training
Create specific ID GET endpoint
- [Instructor] Okay, so now we'll continue basically creating an endpoint to get a specific player with an idea, same approach, some little different nuances, but in the end it's going to be more the same. So let's go in the playerControllers. So we're first going to create the controller. So I'm going to go ahead and do as we've done in the past, create a function, getPlayerWithId. And again, we're going to do an async function req, res. And we're going to try, and then I'm going to again, copy and paste from the catch like so. Be careful because when you create a try, it already has the two curly braces. So if you also copy that curly brace here, you're going to have double and you're going to run into an error. So I'm just going to copy just that. And then we're going to go ahead and create the function that's going to connect to Mongoose and find a player idea. So let's go ahead and get a new object with a player and await response from Mongoose. And we're going to use findByID…