Bird
0
0

You have an API returning 45 items with per_page set to 10. How many pages should the total_pages metadata show?

hard📝 Application Q15 of 15
Rest API - Pagination Patterns

You have an API returning 45 items with per_page set to 10. How many pages should the total_pages metadata show?

A5
B6
C4
D10
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total pages from total items and per_page

    Total pages = total items divided by items per page, rounded up. Here, 45 / 10 = 4.5, rounded up to 5.
  2. Step 2: Confirm the correct total_pages value

    Since 4 pages would only cover 40 items, 5 pages are needed to cover all 45 items.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    Ceil(45/10) = 5 pages [OK]
Quick Trick: Divide total items by per_page, round up [OK]
Common Mistakes:
  • Using floor division instead of ceiling
  • Ignoring leftover items on last page
  • Assuming total_pages equals per_page

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes