0
0
Rest APIprogramming~20 mins

Cursor-based pagination in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cursor Pagination Master
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 cursor-based pagination response?

Given this REST API response for a cursor-based pagination request, what is the value of next_cursor?

Rest API
{
  "data": ["item21", "item22", "item23"],
  "next_cursor": "MjQ=",
  "has_more": true
}
A"item23"
B"MjQ="
C"has_more"
D"data"
Attempts:
2 left
💡 Hint

Look for the field that represents the cursor for the next page.

🧠 Conceptual
intermediate
1:30remaining
Why use cursor-based pagination instead of offset-based pagination?

Which of the following is the main advantage of cursor-based pagination over offset-based pagination?

AIt avoids skipping or duplicating items when data changes during pagination.
BIt allows jumping directly to any page number without sequential access.
CIt requires less server memory to store all pages at once.
DIt always returns the total number of items in the dataset.
Attempts:
2 left
💡 Hint

Think about what happens if new items are added or removed while paginating.

🔧 Debug
advanced
2:00remaining
Identify the error in this cursor-based pagination API response

What error will this API response cause when used for cursor-based pagination?

Rest API
{
  "data": ["item10", "item11"],
  "next_cursor": null,
  "has_more": true
}
AThe <code>next_cursor</code> should be an integer, not null.
BThe <code>has_more</code> field must be false if <code>next_cursor</code> is present.
CThe <code>next_cursor</code> is null but <code>has_more</code> is true, causing inconsistent pagination.
DThe <code>data</code> array is empty, so no items to paginate.
Attempts:
2 left
💡 Hint

Check if the cursor and has_more fields agree on whether more data exists.

📝 Syntax
advanced
1:30remaining
Which option correctly encodes the cursor in a REST API response?

Choose the correct JSON snippet that encodes the cursor as a base64 string for the next page.

A{ "next_cursor": 'aXRlbTQ1' }
B{ "next_cursor": base64_encode("item45") }
C{ "next_cursor": b"aXRlbTQ1" }
D{ "next_cursor": "aXRlbTQ1" }
Attempts:
2 left
💡 Hint

Remember JSON strings must use double quotes and no function calls inside JSON.

🚀 Application
expert
2:00remaining
How many items will be returned after two pages with this cursor-based pagination setup?

An API returns 3 items per page. The dataset has 7 items total. After fetching two pages using cursor-based pagination, how many unique items have been retrieved?

A6
B7
C3
DNone, cursor-based pagination does not guarantee unique items
Attempts:
2 left
💡 Hint

Calculate items per page times pages fetched, but consider total items available.