Bird
0
0

Identify the error in this HAL JSON snippet:

medium📝 Debug Q14 of 15
Rest API - HATEOAS and Linking
Identify the error in this HAL JSON snippet:
{
  "_links": {
    "self": "/orders/123",
    "items": [{ "href": "/items/1" }, { "href": "/items/2" }]
  }
}
AThe JSON is correct as is
B"items" should be a single object, not an array
C"self" link should be an object with an "href" property
D"_links" key should be "links" without underscore
Step-by-Step Solution
Solution:
  1. Step 1: Check the structure of the "self" link

    In HAL, each link must be an object with an href property. Here, "self" is a string, which is incorrect.
  2. Step 2: Verify other parts

    "items" is correctly an array of link objects. The _links key must have an underscore. So only "self" link is wrong.
  3. Final Answer:

    "self" link should be an object with an "href" property -> Option C
  4. Quick Check:

    HAL links = objects with href [OK]
Quick Trick: All HAL links must be objects with href keys [OK]
Common Mistakes:
  • Using string instead of object for single links
  • Removing underscore from _links
  • Thinking arrays are not allowed for multiple links

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes