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?
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.
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.
Final Answer:
Use an object with named related links for clarity -> Option A
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
Master "HATEOAS and Linking" in Rest API
9 interactive learning modes - each teaches the same concept differently