Challenge - 5 Problems
Pagination Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1: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
}
}Attempts:
2 left
💡 Hint
Total pages is total items divided by items per page, rounded up.
✗ Incorrect
There are 5 total items and 2 items per page, so 5/2 = 2.5, rounded up to 3 total pages.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about which number tells you where you are in the list of pages.
✗ Incorrect
The "page" field indicates the current page number being returned in the response.
❓ Predict Output
advanced1: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
}Attempts:
2 left
💡 Hint
Compare current page number with total pages.
✗ Incorrect
Since page 4 is less than total_pages 5, has_next is true.
🔧 Debug
advanced2: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
}Attempts:
2 left
💡 Hint
If total_pages is zero but there are items, what does that mean for pagination?
✗ Incorrect
total_pages should be at least 1 if there are items. Zero misleads client to think no pages exist.
🚀 Application
expert2: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?Attempts:
2 left
💡 Hint
Offset is how many items to skip before starting to fetch the current page.
✗ Incorrect
Offset is zero-based, so for page 1 offset is 0, for page 2 offset is per_page, etc.