Bird
0
0

You want to design a REST API URL to get all comments for a specific article's specific paragraph. Which URL structure best communicates this?

hard📝 Application Q8 of 15
Rest API - URL and Resource Design
You want to design a REST API URL to get all comments for a specific article's specific paragraph. Which URL structure best communicates this?
A/comments/{articleId}/{paragraphId}
B/comments?article={articleId}&paragraph={paragraphId}
C/articles/{articleId}/paragraphs/{paragraphId}/comments
D/articles/comments/{articleId}/{paragraphId}
Step-by-Step Solution
Solution:
  1. Step 1: Understand resource hierarchy

    Comments belong to a paragraph, which belongs to an article, so URL should reflect this nesting.
  2. Step 2: Evaluate each URL option

    /articles/{articleId}/paragraphs/{paragraphId}/comments clearly nests comments under paragraphs under articles, showing the relationship.
  3. Final Answer:

    /articles/{articleId}/paragraphs/{paragraphId}/comments -> Option C
  4. Quick Check:

    Nested URL paths show resource relationships best [OK]
Quick Trick: Nest URLs to show resource hierarchy clearly [OK]
Common Mistakes:
MISTAKES
  • Using flat query parameters instead of path
  • Misordering resource segments
  • Ignoring resource relationships

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes