Complete the code to define a nested route for comments under posts in a REST API.
app.route('/posts/[1]/comments')
In REST API routing, parameters in the URL path are defined with a colon prefix, like ':postId'.
Complete the code to extract the post ID from the request parameters in a nested route handler.
const postId = req.params.[1];The parameter name in the URL is 'postId', so we access it as req.params.postId.
Fix the error in the nested route path to correctly define a route for a specific comment under a post.
app.get('/posts/:postId/comments/[1]', (req, res) => { /* handler */ });
Route parameters must be prefixed with a colon ':' to be recognized as variables.
Fill both blanks to create a nested route that handles updating a comment for a specific post.
app.[1]('/posts/:postId/comments/:commentId', (req, res) => { const postId = req.params.[2]; // update logic });
Use HTTP PUT method for updating, and access the postId parameter from req.params.
Fill all three blanks to define a nested DELETE route for removing a comment from a post.
app.[1]('/posts/:[2]/comments/:[3]', (req, res) => { const postId = req.params.[2]; const commentId = req.params.[3]; // delete logic });
Use the DELETE method and access both postId and commentId parameters to identify the resource to delete.