0
0
Rest APIprogramming~10 mins

Page-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 set the default page size to 10 in the API response.

Rest API
page_size = [1]
Drag options to blanks, or click blank then click option'
A10
B20
C5
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large or too small numbers for page size.
2fill in blank
medium

Complete the code to extract the current page number from the request query parameters.

Rest API
current_page = request.args.get('[1]', 1, type=int)
Drag options to blanks, or click blank then click option'
Apage
Boffset
Csize
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'limit' or 'offset' instead of 'page' for page number.
3fill in blank
hard

Fix the error in calculating the offset for the database query.

Rest API
offset = (current_page [1] 1) * page_size
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 1 instead of subtracting 1 causes wrong offset.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each item id to its name for items on the current page.

Rest API
page_items = {item['[1]']: item['[2]'] for item in items}
Drag options to blanks, or click blank then click option'
Aid
Bname
Ctitle
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'title' or 'value' instead of 'name' for the value.
5fill in blank
hard

Fill all three blanks to filter items with price greater than 100 and create a dictionary with item names as keys and prices as values.

Rest API
filtered_items = {item['[1]']: item['[2]'] for item in items if item['[3]'] > 100}
Drag options to blanks, or click blank then click option'
Aname
Bprice
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' as key or filtering by wrong field.