0
0
Rest APIprogramming~10 mins

Nested resources in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a nested route for comments under posts in a REST API.

Rest API
app.route('/posts/[1]/comments')
Drag options to blanks, or click blank then click option'
A<postId>
BpostId
C{postId}
D:postId
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces or angle brackets instead of colon for URL parameters.
Omitting the colon before the parameter name.
2fill in blank
medium

Complete the code to extract the post ID from the request parameters in a nested route handler.

Rest API
const postId = req.params.[1];
Drag options to blanks, or click blank then click option'
ApostID
BpostId
Cpost_id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than defined in the route.
Using underscores or different casing.
3fill in blank
hard

Fix the error in the nested route path to correctly define a route for a specific comment under a post.

Rest API
app.get('/posts/:postId/comments/[1]', (req, res) => { /* handler */ });
Drag options to blanks, or click blank then click option'
A:commentId
B{commentId}
CcommentId
D<commentId>
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the colon before the parameter name.
Using curly braces or angle brackets instead of colon.
4fill in blank
hard

Fill both blanks to create a nested route that handles updating a comment for a specific post.

Rest API
app.[1]('/posts/:postId/comments/:commentId', (req, res) => {
  const postId = req.params.[2];
  // update logic
});
Drag options to blanks, or click blank then click option'
Aput
BpostId
Cpatch
DcommentId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' or 'post' instead of 'put' or 'patch' for updates.
Accessing the wrong parameter name.
5fill in blank
hard

Fill all three blanks to define a nested DELETE route for removing a comment from a post.

Rest API
app.[1]('/posts/:[2]/comments/:[3]', (req, res) => {
  const postId = req.params.[2];
  const commentId = req.params.[3];
  // delete logic
});
Drag options to blanks, or click blank then click option'
Adelete
BpostId
CcommentId
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' instead of 'delete' as HTTP method.
Mismatching parameter names between URL and req.params.