0
0
Rest APIprogramming~20 mins

Pagination metadata in response in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pagination Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this pagination metadata JSON?
Given this API response snippet, what is the value of total_pages?
Rest API
{
  "data": ["item1", "item2"],
  "pagination": {
    "page": 2,
    "per_page": 2,
    "total_items": 5,
    "total_pages": 3
  }
}
A4
B2
C5
D3
Attempts:
2 left
💡 Hint
Total pages is total items divided by items per page, rounded up.
🧠 Conceptual
intermediate
1:00remaining
Which field is essential to indicate the current page in pagination metadata?
In a paginated API response, which metadata field tells the client which page of results is being returned?
A"page"
B"total_items"
C"per_page"
D"total_pages"
Attempts:
2 left
💡 Hint
Think about which number tells you where you are in the list of pages.
Predict Output
advanced
1:30remaining
What is the value of has_next in this pagination metadata?
Given this pagination metadata, what is the value of has_next if it is defined as page < total_pages?
Rest API
{
  "page": 4,
  "per_page": 10,
  "total_items": 45,
  "total_pages": 5
}
Anull
Bfalse
Ctrue
Derror
Attempts:
2 left
💡 Hint
Compare current page number with total pages.
🔧 Debug
advanced
2:00remaining
What error does this pagination metadata cause?
This API returns pagination metadata with total_pages set to 0 but total_items is 10 and per_page is 5. What problem will this cause?
Rest API
{
  "page": 1,
  "per_page": 5,
  "total_items": 10,
  "total_pages": 0
}
ANo error, metadata is valid
BClient thinks there are no pages and shows no results
CDivision by zero error on client side
DInfinite loop in pagination navigation
Attempts:
2 left
💡 Hint
If total_pages is zero but there are items, what does that mean for pagination?
🚀 Application
expert
2:30remaining
How to calculate offset for database query from pagination metadata?
Given pagination metadata with page and per_page, which formula correctly calculates the offset to fetch items from a database?
Aoffset = (page - 1) * per_page
Boffset = page * per_page
Coffset = per_page - page
Doffset = total_items - per_page
Attempts:
2 left
💡 Hint
Offset is how many items to skip before starting to fetch the current page.