Bird
0
0

You want to design a REST API URL to get all comments for a specific post by a user. Which URL structure best communicates this meaning?

hard📝 Application Q15 of 15
Rest API - URL and Resource Design
You want to design a REST API URL to get all comments for a specific post by a user. Which URL structure best communicates this meaning?
A/user/789/post/456/comments
B/comments/user/789/post/456
C/post/456/comments/user/789
D/comments/post/456/user/789
Step-by-Step Solution
Solution:
  1. Step 1: Identify the resource hierarchy

    The main resource is the user, then the specific post by that user, then the comments on that post.
  2. Step 2: Check URL clarity and order

    /user/789/post/456/comments follows the logical order: user ID, post ID, then comments, making it clear and meaningful.
  3. Step 3: Eliminate confusing options

    Other options mix order or place comments before user/post, which is less clear.
  4. Final Answer:

    /user/789/post/456/comments -> Option A
  5. Quick Check:

    Parent resource then child then sub-resource = B [OK]
Quick Trick: Order URL from general to specific resource [OK]
Common Mistakes:
  • Mixing resource order
  • Placing comments before user/post
  • Ignoring resource hierarchy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes