Bird
0
0

You receive this JSON response but the self link is missing:

medium📝 Debug Q14 of 15
Rest API - HATEOAS and Linking
You receive this JSON response but the self link is missing:
{
  "id": 5,
  "title": "Article",
  "_links": {
    "related": "https://api.example.com/articles/related"
  }
}
What is the best fix to add a self link for the current resource at https://api.example.com/articles/5?
AAdd "self": "https://api.example.com/articles/5" at the root level
BAdd "self_link": "https://api.example.com/articles/5" inside the _links object
CAdd "self": "https://api.example.com/articles/5" inside the _links object
DAdd "link": "https://api.example.com/articles/5" inside the _links object
Step-by-Step Solution
Solution:
  1. Step 1: Identify where self link belongs

    The self link must be inside the _links object with key exactly "self".
  2. 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.
  3. Final Answer:

    Add "self": "https://api.example.com/articles/5" inside the _links object -> Option C
  4. Quick Check:

    Self link key = "self" inside _links [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes