From the course: Building a Website with Node.js and Express.js
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Creating and testing an API endpoint
From the course: Building a Website with Node.js and Express.js
Creating and testing an API endpoint
- [Instructor] We've learned the basics about rest APIs already. Technically, a rest endpoint is no different from any other route in Express. The only difference is that is won't return an html page, but most likely, json. I want to create a route now that can be used to insert a new feedback entry. And it should also return the now updated list of feedback items. So, let's open route, feeback.js, and let's start out by now adding a new method. And it's a post method as well. I'm scrolling all the way down. But this should now be router dot post. And the endpoint should listen under slash API. So, it would be slash feedback slash API. And again, I have a request and a response object and in there, I want to implement my logic. Now of course also data sent via rest has to be validated so I can use basically the same validation rules that I had before for this post route. And it would be pretty redundant to now…