From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Create and test a POST endpoint

Create and test a POST endpoint

- Okay, so at this point we have several endpoints on our server, all of which allow us to get some sort of data from the server. However, one thing we still haven't looked at is how to actually modify data on the server. Now, while we've used get for all of our other endpoints, in order to allow the client to actually make the kind of modifications we want them to be able to make, we're going to use app.post, which allows the client to make post requests to a certain end point. And for those of you who don't know, the main difference between a post request and a get request is that with a post request, you're allowed to send extra data along with the request. The client is able to send extra data along with that request that is. So what we're going to do is define a post endpoint and what this endpoint is going to allow the client to do is send a new person object that we want to add to the fake database and it'll add that and then send a response back. So for our endpoint, we're…

Contents