0
0
Rest APIprogramming~20 mins

Query parameters for filtering in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Query Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this REST API filtering example?

Consider a REST API endpoint that returns a list of products. The URL is /products?category=books&price_lt=20. The server filters products by category and price less than 20.

Given the following products data:

[{"id":1,"category":"books","price":15},{"id":2,"category":"books","price":25},{"id":3,"category":"electronics","price":10}]

What is the JSON response returned by the server?

A[{"id":1,"category":"books","price":15}]
B[{"id":1,"category":"books","price":15},{"id":2,"category":"books","price":25}]
C[{"id":3,"category":"electronics","price":10}]
D[]
Attempts:
2 left
💡 Hint

Remember the filter is for category 'books' and price less than 20.

🧠 Conceptual
intermediate
1:30remaining
Which query parameter correctly filters users by age greater than 30?

You want to filter users whose age is greater than 30 using query parameters in a REST API. Which of the following query parameters is the correct way to express this?

Aage>30
Bage=gt:30
Cage_gt=30
Dage_greater_than=30
Attempts:
2 left
💡 Hint

Look for the common convention using suffixes like '_gt' for greater than.

🔧 Debug
advanced
2:30remaining
Why does this filtering query return no results?

A REST API endpoint /items?color=red&size=medium is expected to return items that are red and medium size. But it returns an empty list. The database has items matching these filters.

What is the most likely cause?

AThe query parameters are case-sensitive and 'red' should be 'Red'.
BThe API treats multiple query parameters as OR instead of AND.
CThe API expects comma-separated values in a single parameter, not multiple parameters.
DThe database has no items with color 'red' and size 'medium'.
Attempts:
2 left
💡 Hint

Think about how multiple query parameters combine filters.

📝 Syntax
advanced
2:00remaining
Which query parameter syntax is invalid for filtering by date range?

You want to filter records between two dates using query parameters. Which of the following is NOT a valid syntax?

Adate=2023-01-01..2023-01-31
Bdate_gte=2023-01-01&date_lte=2023-01-31
Cdate_between=2023-01-01,2023-01-31
Ddate>=2023-01-01&date<=2023-01-31
Attempts:
2 left
💡 Hint

Check which characters are allowed in URL query parameters without encoding.

🚀 Application
expert
3:00remaining
How many items are returned by this complex filter?

An API endpoint /orders?status=shipped&total_gt=100&date_lt=2024-01-01 filters orders with status 'shipped', total greater than 100, and date before 2024-01-01.

Given the orders data:

[{"id":1,"status":"shipped","total":150,"date":"2023-12-15"},{"id":2,"status":"pending","total":200,"date":"2023-11-20"},{"id":3,"status":"shipped","total":90,"date":"2023-12-01"},{"id":4,"status":"shipped","total":120,"date":"2024-02-01"}]

How many orders match all filters?

A1
B2
C3
D0
Attempts:
2 left
💡 Hint

Check each order against all three conditions carefully.