res.render(). How easy is that?
catalogmodule, so to get the view for our list of books you would access
/catalog/books. Setting the Library project up to also serve JSON would be as easy as creating a different router module called
apiand then adjusting the controllers so that
/catalog/bookswould serve up the HTML list of our books and
/api/bookswould serve up the same information as JSON.
/api/posts/:postid/commentsor anything else. However, REST (an acronym for Representational State Transfer) is a popular and common organizational method for your APIs. It can be beneficial to follow a pattern such as REST when organizing your APIs because doing so will make using it that much easier for you in the long run and if you ever want to make your API public, other users will have a better idea of how to get the information they're seeking.
/saveNewItemInDatabasewe refer directly to the resource and then use the HTTP verbs to determine what action we are taking.
/postsand then get a specific post from
/posts/:postid. You can also nest collections in this way. To get the list of comments on a single post you would access
/posts/:postid/commentsand then to get a single comment:
/posts, so in your express app you would respond to
app.get("/posts")with a list of all posts.
PUTto the URI of the specific post you're updating.