Link relations help clients understand how different parts of an API response connect to each other. They make navigation and interaction easier by showing what links mean.
When you want to guide users to related resources in an API response.
When you want to provide navigation links like next page or previous page in paginated data.
When you want to describe the purpose of a link, like 'edit', 'delete', or 'self'.
When you want to make your API responses more self-explanatory and easier to use.
When you want to follow REST API best practices for discoverability.
Syntax
Rest API
{
"_links": {
"self": { "href": "URL to this resource" },
"related": { "href": "URL to related resource" },
"next": { "href": "URL to next page/resource" }
},
"data": { ... }
}
The _links object groups all link relations in the response.
Each link relation has a name (like self, next) and an href URL.
Examples
This response shows a user with links to itself and to the user's friends.
What is wrong with the link relations in this response?
medium
A. The 'edit' relation uses 'url' instead of 'href'
B. The 'self' relation should not be included
C. The 'href' value for 'self' is missing a domain
D. The '_links' key should be named 'links'
Solution
Step 1: Check the property names inside link relations
Standard link relations use 'href' to specify the URL, not 'url'.
Step 2: Identify the incorrect property
The 'edit' relation incorrectly uses 'url' instead of 'href'.
Final Answer:
The 'edit' relation uses 'url' instead of 'href' -> Option A
Quick Check:
Link relation URLs must use 'href' key [OK]
Hint: Link URLs always use 'href', not 'url' [OK]
Common Mistakes:
Thinking 'url' is acceptable instead of 'href'
Expecting full domain in href for relative URLs
Renaming '_links' to 'links' incorrectly
5. You want to design a REST API response for a blog post that includes links to the post itself, the author's profile, and comments. Which JSON structure correctly uses link relations to represent these?
Each link relation should be an object with an 'href' key inside the '_links' object.
Step 2: Evaluate each option's structure
{ "_links": { "self": { "href": "/posts/10" }, "author": { "href": "/users/5" }, "comments": { "href": "/posts/10/comments" } } } correctly uses '_links' with 'self', 'author', and 'comments' keys, each having an 'href' URL. Options B and D use 'url' instead of 'href', and C uses strings instead of objects.