Bird
0
0

You want to design a REST API path to access all comments on a specific post (ID 20) of a user (ID 5). Which path correctly follows hierarchical resource conventions?

hard📝 Application Q8 of 15
Rest API - URL and Resource Design
You want to design a REST API path to access all comments on a specific post (ID 20) of a user (ID 5). Which path correctly follows hierarchical resource conventions?
A/users/posts/comments/5/20
B/users/5/posts/20/comments
C/comments/posts/20/users/5
D/posts/20/users/5/comments
Step-by-Step Solution
Solution:
  1. Step 1: Identify resource hierarchy

    User is the top-level resource, posts are nested under users, comments are nested under posts.
  2. Step 2: Construct the correct path

    The path should be /users/5/posts/20/comments to access comments of post 20 by user 5.
  3. Final Answer:

    /users/5/posts/20/comments -> Option B
  4. Quick Check:

    Parent to child order with IDs = correct path [OK]
Quick Trick: Order: parent resource ID, child resource ID, then sub-resource [OK]
Common Mistakes:
MISTAKES
  • Reversing resource order
  • Omitting IDs
  • Placing comments before posts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes