Bird
0
0

You want to design a REST API URL to access a comment with ID 555 on a post with ID 101. Which URL correctly uses resource identifiers to reflect this nested relationship?

hard📝 Application Q15 of 15
Rest API - URL and Resource Design
You want to design a REST API URL to access a comment with ID 555 on a post with ID 101. Which URL correctly uses resource identifiers to reflect this nested relationship?
A/posts/101/comments/555
B/comments/555/posts/101
C/posts/comments/555/101
D/posts/555/comments/101
Step-by-Step Solution
Solution:
  1. Step 1: Understand resource hierarchy

    The comment belongs to a post, so the post resource should come first in the URL.
  2. Step 2: Check each URL option

    /posts/101/comments/555 correctly places the post ID first, then the comments resource with its ID. Other options mix the order or IDs incorrectly.
  3. Final Answer:

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

    Parent resource ID before child resource ID [OK]
Quick Trick: Parent resource ID comes before child resource ID in URL [OK]
Common Mistakes:
MISTAKES
  • Reversing parent and child resource order
  • Mixing IDs between resources
  • Placing IDs in wrong path segments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes