Full stack web development Course | 116. Swag Shop API: Posting Products

Published: 01 January 1970
on channel: WB Web Development Solutions
5,075
68

Full-stack web development Tutorial in Just 3 Weeks

Week 3: Day 2
Section 12: Intro to Node, Mongo, & REST APIs
Tutorial 116: Swag Shop API: Posting Products

In this video tutorial, we are going to learn to add data to our Mongo shell using post request and check it on POSTMAN.

LECTURE CONTENT
00:00:00 Introduction
00:02:05 Creating a Post request
00:08:40 Checking the post request in POSTMAN
00:11:25 Exit command
00:12:43 End


Step 1: Add the new product to the collection using app.post('/collection' , function(request,response){}
The post is an HTTP method used when we need to send some additional information inside the body of the request to the server.
/ is the path or route
The function is the middleware function. The middleware function is a function that has access to the request object, response object, and the next function in the applications request-response cycle. These functions are used to modify request and response objects for tasks like parsing request body, adding response headers, etc.
Request(req) is the HTTP request argument to the middleware function
Response(res)is the HTTP response argument for the middleware function

Example- app.post('/product',function(request,response){error message});

Step 2: Enter the message to be displayed to the user the product is saved or not saved. If it is saved it will display "saved product" but if not saved it will display "could not save product".
Step 3: Open POSTMAN. Check the post request in POSTMAN.
Step 4: Open the terminal and use the following command:
Show dbs - to see all the databases present in your system
Use dbs- to use a particular database
Show collection- to use a particular collection present in that particular database
Find()- to display the data present in the collection
Step 5: Enter Exit to get out of the Mongo shell. Never leave the shell open. It gets to hang and your data gets corrupted.


Watch video Full stack web development Course | 116. Swag Shop API: Posting Products online without registration, duration hours minute second in high quality. This video was added by user WB Web Development Solutions 01 January 1970, don't forget to share it with your friends and acquaintances, it has been viewed on our site 5,07 once and liked it 6 people.