Bird
0
0

You want to design a REST API for managing comments on blog posts. Which of the following is the best noun-based resource path to list all comments for a post with ID 42?

hard📝 Application Q15 of 15
Rest API - URL and Resource Design
You want to design a REST API for managing comments on blog posts. Which of the following is the best noun-based resource path to list all comments for a post with ID 42?
A/posts/42/comments
B/getCommentsForPost/42
C/comments?postId=42
D/postComments/42
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested resource naming

    Comments belong to posts, so nesting comments under posts is clear and RESTful.
  2. Step 2: Evaluate the options

    Option '/posts/42/comments' uses plural nouns and shows the relationship clearly without verbs or query parameters.
  3. Final Answer:

    /posts/42/comments -> Option A
  4. Quick Check:

    Nested plural nouns show resource hierarchy [OK]
Quick Trick: Use nested plural nouns for related resources [OK]
Common Mistakes:
  • Using verbs in paths like 'getCommentsForPost'
  • Using query parameters instead of nested paths
  • Using singular nouns inconsistently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes