From the course: MERN Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Create a PUT endpoint
- [Instructor] Okay, so now let's work on the PUT endpoint, which will allow us to update a single player. So let's go back to controllers again and it's the same process. So what we're going to do is copy what we've done. This one here and then just paste it just below. And we're going to call this one UpdatePlayer. And we need the request, response. And then what we need to do is use again player but as opposed to findById. We need to findOne AndUpdate. And then we need to have a few things here, so let's erase that first. And let's open the curly braces. And we need to have an ID first, so we need to have the ID in order to update the player. So what we're going to do is do req.params.PlayerId again same process as before. Now we need to pass right after the request body. And why we need to do that. So basically we need to find first the ID that we want to update with the PlayerId. So again if we go back to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.