Bird
0
0

How can you combine related resource links with pagination info in a REST API response for a list of comments?

hard📝 Application Q9 of 15
Rest API - HATEOAS and Linking
How can you combine related resource links with pagination info in a REST API response for a list of comments?
A{ "comments": [...], "links": { "next": {"href": "/comments?page=2"}, "prev": {"href": "/comments?page=1"} } }
B{ "comments": [...], "next": "/comments?page=2", "prev": "/comments?page=1" }
C{ "comments": [...], "pagination": { "next": "/comments?page=2", "prev": "/comments?page=1" } }
D{ "comments": [...], "links": [ {"rel": "next", "href": "/comments?page=2"}, {"rel": "prev", "href": "/comments?page=1"} ] }
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining links and pagination

    Pagination links are related resource links and should be grouped under "links" with href objects.
  2. Step 2: Evaluate options for best practice

    { "comments": [...], "links": { "next": {"href": "/comments?page=2"}, "prev": {"href": "/comments?page=1"} } } groups "next" and "prev" inside "links" as objects with href, matching common REST API patterns.
  3. Final Answer:

    Pagination links grouped under 'links' with href objects -> Option A
  4. Quick Check:

    Pagination links format = { "comments": [...], "links": { "next": {"href": "/comments?page=2"}, "prev": {"href": "/comments?page=1"} } } [OK]
Quick Trick: Put pagination URLs inside 'links' with href keys [OK]
Common Mistakes:
  • Placing pagination links outside 'links' object
  • Using arrays instead of objects for links
  • Not using href keys for URLs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes