Bird
0
0

You want to design an API to manage blog posts and their comments. Which endpoint naming is best for retrieving all comments of a post with ID 45?

hard📝 Application Q8 of 15
Rest API - URL and Resource Design
You want to design an API to manage blog posts and their comments. Which endpoint naming is best for retrieving all comments of a post with ID 45?
A/post/45/comment/list
B/posts/45/comment
C/post/45/comments
D/posts/45/comments
Step-by-Step Solution
Solution:
  1. Step 1: Use plural for collections and singular for single resources

    Posts and comments are collections, so plural form is preferred.
  2. Step 2: Combine plural post resource with post ID and plural comments

    The correct endpoint is /posts/45/comments to get all comments for post 45.
  3. Final Answer:

    /posts/45/comments -> Option D
  4. Quick Check:

    Nested plural resources with ID = A [OK]
Quick Trick: Use plural resource names and IDs for nested collections [OK]
Common Mistakes:
  • Mixing singular and plural inconsistently
  • Adding unnecessary /list suffix
  • Using singular for collections

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes