Bird
0
0

You want to include a list of products inside a HAL response for a category resource. How should you structure the _embedded section to follow HAL best practices?

hard📝 Application Q8 of 15
Rest API - HATEOAS and Linking
You want to include a list of products inside a HAL response for a category resource. How should you structure the _embedded section to follow HAL best practices?
A"_links": { "products": [ { "href": "/products/1" }, { "href": "/products/2" } ] }
B"_embedded": { "products": [ { "name": "Pen" }, { "name": "Notebook" } ] }
C"_embedded": { "products": [ { "name": "Pen", "_links": { "self": { "href": "/products/1" } } }, { "name": "Notebook", "_links": { "self": { "href": "/products/2" } } } ] }
D"products": [ { "name": "Pen" }, { "name": "Notebook" } ]
Step-by-Step Solution
Solution:
  1. Step 1: Structure embedded resources with links

    HAL best practice is to embed related resources inside _embedded with each resource including its own _links section.
  2. Step 2: Evaluate options

    "_embedded": { "products": [ { "name": "Pen", "_links": { "self": { "href": "/products/1" } } }, { "name": "Notebook", "_links": { "self": { "href": "/products/2" } } } ] } correctly embeds products with their own self links. "_embedded": { "products": [ { "name": "Pen" }, { "name": "Notebook" } ] } lacks links, C misuses _links, and D is missing _embedded.
  3. Final Answer:

    "_embedded": { "products": [ { "name": "Pen", "_links": { "self": { "href": "/products/1" } } }, { "name": "Notebook", "_links": { "self": { "href": "/products/2" } } } ] } -> Option C
  4. Quick Check:

    Embed with _embedded and include _links per resource [OK]
Quick Trick: Embed resources with their own _links inside _embedded [OK]
Common Mistakes:
  • Omitting _links inside embedded resources
  • Placing embedded resources outside _embedded
  • Using _links incorrectly for embedded lists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes