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 POST endpoint
From the course: MERN Essential Training
Create POST endpoint
- [Instructor] Okay, so now we'll actually add the post endpoint so we can add new items into your database. So the first thing I'm going to do is start playing in the playerControllers area. So, you go into controllers. You open up that file here. I'm going to close this for a second, and I'm going to start doing a few things such as importing mongoose from mongoose, and then I'm going to import the player schema that we've just completed in the previous video, PlayerSchema from models/playerModel. There you go. Now we're going to create a player with the mongoose, and again, IntelliSense trying to help me. And then we're going to import the model, pass the playerModel with the PlayerSchema. So basically, what we're doing is telling the controller that we're going to create, momentarily, if you create a player, it needs to be using this PlayerSchema. So, if the values that we're passing to this schema or the controller are not fitting to the PlayerSchema, then it's going to throw us…