What is the best fix to add a self link for the current resource at https://api.example.com/articles/5?
medium
A. Add "self": "https://api.example.com/articles/5" at the root level
B. Add "self_link": "https://api.example.com/articles/5" inside the _links object
C. Add "self": "https://api.example.com/articles/5" inside the _links object
D. Add "link": "https://api.example.com/articles/5" inside the _links object
Solution
Step 1: Identify where self link belongs
The self link must be inside the _links object with key exactly "self".
Step 2: Choose correct key and location
Add "self": "https://api.example.com/articles/5" inside the _links object adds the correct key "self" with the URL inside _links. Other options use wrong keys or wrong placement.
Final Answer:
Add "self": "https://api.example.com/articles/5" inside the _links object -> Option C
Quick Check:
Self link key = "self" inside _links [OK]
Hint: Self link must be 'self' key inside _links object [OK]
Common Mistakes:
Using wrong key names like self_link or link
Placing self link outside _links object
Omitting the self link entirely
5. You want to design a REST API response for a user resource with ID 7. Which JSON snippet correctly includes a self link and a related link to the user's orders at https://api.example.com/users/7/orders?
The self link must be under _links with key "self" and URL "https://api.example.com/users/7".
Step 2: Choose appropriate key for related orders link
Using "orders" for the orders link is a standard practice to indicate the related resource. {
"id": 7,
"name": "Alice",
"_links": {
"self": "https://api.example.com/users/7",
"orders": "https://api.example.com/users/7/orders"
}
} uses "orders" correctly.
Step 3: Check other options for correctness
{
"id": 7,
"name": "Alice",
"_links": {
"self": "https://api.example.com/users/7",
"orders": "https://api.example.com/users/7/orders"
}
} uses "orders" key which is standard. {
"id": 7,
"name": "Alice",
"links": {
"self": "https://api.example.com/users/7",
"orders": "https://api.example.com/users/7/orders"
}
} uses "links" instead of "_links". {
"id": 7,
"name": "Alice",
"_links": {
"self_link": "https://api.example.com/users/7",
"orders_link": "https://api.example.com/users/7/orders"
}
} uses non-standard keys "self_link" and "orders_link". The option with "related": "https://api.example.com/users/7/orders" uses a generic rel name which is less descriptive for the specific orders resource.