Bird
Raised Fist0

You want to add a self link to a nested resource in your API response. The resource is a comment with ID 7 belonging to post ID 3. Which is the correct self link URL?

hard🚀 Application Q8 of Q15
Rest API - HATEOAS and Linking
You want to add a self link to a nested resource in your API response. The resource is a comment with ID 7 belonging to post ID 3. Which is the correct self link URL?
A/comments/7
B/posts/comments/7
C/posts/7/comments/3
D/posts/3/comments/7
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested resource URL structure

    Nested resources include parent resource ID followed by child resource ID in the URL path.
  2. Step 2: Construct the correct URL

    Post ID 3 then comment ID 7 gives "/posts/3/comments/7".
  3. Final Answer:

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

    Nested resource URL = parent ID + child ID [OK]
Quick Trick: Nested self link includes parent and child IDs in path [OK]
Common Mistakes:
MISTAKES
  • Omitting parent resource ID
  • Swapping parent and child IDs
  • Using incorrect path order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes