app.post('/messages', (req,res) => { console.log(req.body) res.sendStatus(200) })
2- Make sure nodemon is still running
3- Let's download Postman app to test the post functionality. Then install in the system.
4- Open Postman and choose "Post" from the address dropdown
5- In the request URL field, add your post end point address localhost:3000/messages
6- Go to the Body tab and select JSON from the dropdown
7- Then, in the body area, we add our message object:
{"name": "Jane", "message": "from postman"}
8- Click the Send button within Postman, if the post service works properly, you will see a 200 OK status message
9- If you check the console, you will find an undefined message, this is because we tried to console log the body of the JSON but the body couldn't be read/parsed by Express app.
console.log(req.body)
This will be explained in the next entry.
No comments:
Post a Comment