From the course: Learning Node.js

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Create a post messages service

Create a post messages service - Node.js Tutorial

From the course: Learning Node.js

Create a post messages service

- [Instructor] Let's begin by creating a new message post and point in Node. So let's open up our server.js. Then, let's copy our app.get on line 11 through line 13. And we'll paste it below. Next, let's change the get to a post. Then, since we're not responding with a message list, instead of using res.send on line 16, we use res.sendStatus and we'll pass in 200 for 200 OK. This will let the client know that everything went well. Finally as the test, above our res.sendStatus we'll use a console.log to display the req.body to see what data we get in our body. In order to try this, we can't easily send a post request with the browser, so we'll use an app called Postman. You can get Postman from the Chrome app store or as a standalone app for Windows or Mac. Once Postman starts, let's update the URL with our post endpoint of localhost:3000/messages. Then in the dropdown on the left, instead of using the GET action, we'll specify a POST action. Then finally, we can go to the body tab and…

Contents