0
0
Rest APIprogramming~10 mins

Query parameters for filtering 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 get the value of the 'category' query parameter from the URL.

Rest API
category = request.args.get('[1]')
Drag options to blanks, or click blank then click option'
Acategory
Bfilter
Csort
Dpage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name like 'filter' or 'sort'.
Forgetting to use quotes around the parameter name.
2fill in blank
medium

Complete the code to check if the 'price' query parameter exists in the request.

Rest API
if '[1]' in request.args:
Drag options to blanks, or click blank then click option'
Aoffset
Bfilter
Climit
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for a parameter name that does not exist.
Not using quotes around the parameter name.
3fill in blank
hard

Fix the error in the code to convert the 'limit' query parameter to an integer safely.

Rest API
limit = int(request.args.get('[1]', 10))
Drag options to blanks, or click blank then click option'
Alimit
Boffset
Cpage
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name like 'offset' or 'page'.
Not providing a default value causing errors if parameter is missing.
4fill in blank
hard

Fill both blanks to filter items by 'category' and 'max_price' query parameters.

Rest API
category = request.args.get('[1]')
max_price = request.args.get('[2]')
Drag options to blanks, or click blank then click option'
Acategory
Bmin_price
Cmax_price
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'min_price' with 'max_price'.
Using generic names like 'price' instead of 'max_price'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering items where 'category' matches and 'price' is less than max_price.

Rest API
filtered_items = {item: data[item] for item in data if data[item]['[1]'] == [2] and data[item]['[3]'] < max_price}
Drag options to blanks, or click blank then click option'
Acategory
B'electronics'
Cprice
Dstock
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'stock' instead of 'price'.
Not quoting string values like 'electronics'.