Full stack web development Course | 118. Swag Shop API: Populating Data
5.2K views on YouTube
Full-stack web development Tutorial in Just 3 Weeks
Week 3: Day 2
Section 12: Intro to Node, Mongo, & REST APIs
Tutorial 118: Swag Shop API: Populating Data
Lecture content
00:00:00 introduction
00:00:29 creating a new wishlist using Put request
00:02:15 verifying the put request in POSTMAN
00:03:16 Finding the list of wishlists using get request
00:04:57 Adding data to the newly created wishlist using Put request
00:14:45 Populating the data
00:19:00 End
In this video tutorial, we are going to learn about how to create a new wishlist, add items to it and then get the list of all the wishlists present in our collection named product. We are going to use all the three- get, put, and post parameters in this video.
Step 1: We do a Post request to create a new wishlist.
app.post(‘/wishlist’,function(request, response){ error message });
If the new wishlist is found it will display “wishlist” else “could not find wishlist”.
Step 2: We do a get request to find the list of
Wishlists present in our collection I.e. product.
app.get(‘/wishlist’,function(request,response) { });
Step 3: we do a put request to add new data to the newly created wishlist and check the data in Postman.
app.put(‘/wishlist/product/add’, function(request, response){ });
Check it in POSTMAN.
Step 4: Populate the data
In the get request, modify the statement into
app.get(‘/wishlist’,function(request,response)
{ wishlist.find({}).populate({path:’product’, model:’product’}) exec(function(err,wishlist{ error message}));
populate() function in mongoose is used for populating the data inside the reference.