Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a self link in a REST API?
A self link is a URL included in a REST API response that points to the current resource itself. It helps clients easily find or refresh the resource.
Click to reveal answer
beginner
Why include a self link in a REST API response?
Including a self link improves navigation by letting clients know the exact URL of the current resource, making it easier to update or retrieve it again.
Click to reveal answer
beginner
How is a self link typically represented in a REST API JSON response?
It is often included as a field named "self" or under a "links" object, containing the URL string of the current resource.
Click to reveal answer
beginner
Give an example of a self link in a REST API response.
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.