A second model
Adding a route for comments
Summary
In this lesson, we set up a route for adding comments to an article. This involves modifying the routes.js
configuration file to define an endpoint that accepts POST requests.
The new route:
Uses a POST method.
Takes the article ID as a parameter.
Maps to the
create-comment
action in the Comment controller.
Currently, the create-comment
action does not exist, but we will create it in the next lesson.
Transcript
Okay, so now we are in our routes.js
config file. What we want to do in this lesson is pretty simple. We're going to set up a route that allows us to add a new comment to an article.
To do this, we just need to add a single entry in routes.js
. We will:
Make it a POST route to
article/:id/comments
.Use the article ID as a parameter to specify which article the comment belongs to.
Map it to a controller action in
CommentController
.
The route looks like this:
'POST /article/:id/comments': 'comment/create-comment'
The create-comment
action does not exist yet, but in the next lesson, we will create it.
Full Course
USD