Bird
Raised Fist0

How can you represent pagination links (first, prev, next, last) in a HAL response for a collection resource?

hard🚀 Application Q9 of Q15
Rest API - HATEOAS and Linking
How can you represent pagination links (first, prev, next, last) in a HAL response for a collection resource?
A"_embedded": { "pagination": [ "first", "prev", "next", "last" ] }
B"_links": { "first": { "href": "/items?page=1" }, "prev": { "href": "/items?page=2" }, "next": { "href": "/items?page=4" }, "last": { "href": "/items?page=10" } }
C"pagination": { "first": "/items?page=1", "prev": "/items?page=2" }
D"_links": [ { "rel": "first", "href": "/items?page=1" }, { "rel": "next", "href": "/items?page=4" } ]
Step-by-Step Solution
Solution:
  1. Step 1: Recall how HAL represents links

    HAL uses the _links object with named keys for each relation (rel) and their href URLs.
  2. Step 2: Check options for correct structure

    "_links": { "first": { "href": "/items?page=1" }, "prev": { "href": "/items?page=2" }, "next": { "href": "/items?page=4" }, "last": { "href": "/items?page=10" } } correctly uses named keys with href objects. "_embedded": { "pagination": [ "first", "prev", "next", "last" ] } misuses _embedded, C lacks _links, and D uses an array which is invalid in HAL.
  3. Final Answer:

    "_links": { "first": { "href": "/items?page=1" }, "prev": { "href": "/items?page=2" }, "next": { "href": "/items?page=4" }, "last": { "href": "/items?page=10" } } -> Option B
  4. Quick Check:

    Pagination links go inside _links as named href objects [OK]
Quick Trick: Use _links with named keys for pagination URLs [OK]
Common Mistakes:
MISTAKES
  • Placing pagination in _embedded
  • Using arrays instead of objects for _links
  • Omitting _links wrapper

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes