Bird
Raised Fist0

You have an API that returns user comments with cursor-based pagination. You want to fetch all comments but the API limits each response to 5 items. How should you implement fetching all comments?

hard🚀 Application Q8 of Q15
Rest API - Pagination Patterns

You have an API that returns user comments with cursor-based pagination. You want to fetch all comments but the API limits each response to 5 items. How should you implement fetching all comments?

ARepeatedly request pages using the returned cursor until next_cursor is null
BRequest all comments at once by setting limit to a very high number
CUse offset-based pagination with page numbers instead
DRequest only the first page and ignore the cursor
Step-by-Step Solution
Solution:
  1. Step 1: Understand API limit and cursor usage

    The API limits responses to 5 items and provides a cursor for next page.
  2. Step 2: Implement loop to fetch all pages

    Use the cursor from each response to request the next page repeatedly until next_cursor is null.
  3. Final Answer:

    Repeatedly request pages using the returned cursor until next_cursor is null -> Option A
  4. Quick Check:

    Fetch all pages by looping with cursor until null [OK]
Quick Trick: Loop requests with cursor until next_cursor is null to get all data [OK]
Common Mistakes:
MISTAKES
  • Trying to get all data in one request ignoring limit
  • Switching to offset pagination unnecessarily
  • Ignoring cursor and fetching only first page

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes