0
0
Rest APIprogramming~10 mins

Cursor-based pagination in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the cursor parameter from the request query.

Rest API
cursor = request.args.get('[1]')
Drag options to blanks, or click blank then click option'
Apage
Blimit
Ccursor
Doffset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'page' or 'limit' instead of 'cursor' to get the pagination token.
2fill in blank
medium

Complete the code to decode the cursor string into an integer ID.

Rest API
start_id = int(base64.b64decode([1]).decode('utf-8')) if cursor else 0
Drag options to blanks, or click blank then click option'
Acursor
Boffset
Climit
Dpage
Attempts:
3 left
💡 Hint
Common Mistakes
Decoding a wrong variable like 'limit' or 'offset' instead of 'cursor'.
3fill in blank
hard

Fix the error in the SQL query to fetch items after the cursor ID.

Rest API
"SELECT * FROM items WHERE id [1] %s ORDER BY id ASC LIMIT %s"
Drag options to blanks, or click blank then click option'
A>=
B<
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '=' which fetches wrong or duplicate items.
4fill in blank
hard

Fill both blanks to encode the last item's ID as the next cursor and include it in the response.

Rest API
next_cursor = base64.b64encode(str(items[-[1]].[2]).encode('utf-8')).decode('utf-8') if items else None
Drag options to blanks, or click blank then click option'
A1
Bid
Cname
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 or attribute 'name' instead of 'id'.
5fill in blank
hard

Fill all three blanks to build the JSON response with items, next cursor, and a flag indicating more data.

Rest API
response = {
  '[1]': items,
  '[2]': next_cursor,
  '[3]': len(items) == limit
}
Drag options to blanks, or click blank then click option'
Adata
Bnext_cursor
Chas_more
Dresults
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'data' or 'nextPage' that don't match the expected API format.