Bird
Raised Fist0

You want to design a REST API response for a blog post that includes related links to the author and comments. Which JSON structure correctly shows these related resource links?

hard🚀 Application Q15 of Q15
Rest API - HATEOAS and Linking
You want to design a REST API response for a blog post that includes related links to the author and comments. Which JSON structure correctly shows these related resource links?
A{ "id": 101, "title": "REST APIs", "related": { "author": "https://api.example.com/users/42", "comments": "https://api.example.com/posts/101/comments" } }
B{ "id": 101, "title": "REST APIs", "related": [ "https://api.example.com/users/42", "https://api.example.com/posts/101/comments" ] }
C{ "id": 101, "title": "REST APIs", "related": "https://api.example.com/users/42, https://api.example.com/posts/101/comments" }
D{ "id": 101, "title": "REST APIs", "related": null }
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to represent multiple related links

    When multiple related resources exist, it's best to use an object with named keys for clarity, not a list or comma-separated string.
  2. Step 2: Evaluate each option

    { "id": 101, "title": "REST APIs", "related": { "author": "https://api.example.com/users/42", "comments": "https://api.example.com/posts/101/comments" } } uses an object with keys "author" and "comments" pointing to URLs, which is clear and correct. { "id": 101, "title": "REST APIs", "related": [ "https://api.example.com/users/42", "https://api.example.com/posts/101/comments" ] } uses a list without labels, making it unclear. { "id": 101, "title": "REST APIs", "related": "https://api.example.com/users/42, https://api.example.com/posts/101/comments" } uses a string with comma-separated URLs, which is not standard. { "id": 101, "title": "REST APIs", "related": null } has null, which provides no links.
  3. Final Answer:

    Use an object with named related links for clarity -> Option A
  4. Quick Check:

    Multiple related links = object with named URLs [OK]
Quick Trick: Use named keys for multiple related links in JSON [OK]
Common Mistakes:
MISTAKES
  • Using arrays without labels for related links
  • Combining URLs in one string
  • Leaving related links empty or null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes