Bird
Raised Fist0
Rest APIprogramming~20 mins

Multiple filter parameters in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Multiple Filters
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of filtering with multiple query parameters
Consider a REST API endpoint that filters products by category and price range using query parameters. What is the output when requesting /products?category=books&min_price=10&max_price=20 if the database contains:
  • Book A: category=books, price=15
  • Book B: category=books, price=25
  • Pen: category=stationery, price=5
Rest API
products = [
  {"name": "Book A", "category": "books", "price": 15},
  {"name": "Book B", "category": "books", "price": 25},
  {"name": "Pen", "category": "stationery", "price": 5}
]

filtered = [p for p in products if p["category"] == "books" and 10 <= p["price"] <= 20]
print(filtered)
A[{'name': 'Pen', 'category': 'stationery', 'price': 5}]
B[{'name': 'Book B', 'category': 'books', 'price': 25}]
C[]
D[{'name': 'Book A', 'category': 'books', 'price': 15}]
Attempts:
2 left
💡 Hint
Filter by category first, then check price range.
🧠 Conceptual
intermediate
1:30remaining
Understanding multiple filter parameters in REST APIs
When a REST API endpoint supports multiple filter parameters like ?color=red&size=medium, how are these filters usually combined to select results?
AFilters are combined with AND logic, so results must match all filters.
BFilters are combined with OR logic, so results can match any filter.
CFilters are ignored and all results are returned.
DFilters are combined randomly for each request.
Attempts:
2 left
💡 Hint
Think about how multiple conditions narrow down results.
🔧 Debug
advanced
2:30remaining
Identify the error in handling multiple filters
This code snippet tries to filter users by age and city from query parameters but returns incorrect results. What is the error?
Rest API
def filter_users(users, age=None, city=None):
    filtered = users
    if age:
        filtered = [u for u in users if u['age'] == age]
    if city:
        filtered = [u for u in users if u['city'] == city]
    return filtered

users = [
    {'name': 'Alice', 'age': 30, 'city': 'NY'},
    {'name': 'Bob', 'age': 25, 'city': 'LA'},
    {'name': 'Carol', 'age': 30, 'city': 'LA'}
]

result = filter_users(users, age=30, city='LA')
print(result)
AThe second filter overwrites the first, so only city filter applies.
BThe function returns an empty list because users is empty.
CThe function raises a TypeError due to wrong parameter types.
DThe function filters correctly and returns both conditions.
Attempts:
2 left
💡 Hint
Check how the filtered list is updated after each condition.
📝 Syntax
advanced
1:30remaining
Syntax error in parsing multiple filter parameters
Which option correctly parses multiple filter parameters from a URL query string in Python?
Rest API
from urllib.parse import parse_qs
query = 'type=fruit&type=vegetable&color=red'
params = parse_qs(query)
print(params)
A{'type': 'vegetable', 'color': 'red'}
B{'type': ['fruit', 'vegetable'], 'color': ['red']}
CSyntaxError: invalid syntax
D{'type': ['fruit'], 'color': ['red']}
Attempts:
2 left
💡 Hint
parse_qs returns lists for each key.
🚀 Application
expert
3:00remaining
Combining multiple filters with optional parameters
You want to build a REST API endpoint that filters orders by optional parameters: status, min_total, and max_total. Which code snippet correctly applies all filters only if parameters are provided?
A
filtered = []
for o in orders:
  if status and o['status'] != status:
    continue
  if min_total and o['total'] &lt; min_total:
    continue
  if max_total and o['total'] &gt; max_total:
    continue
  filtered.append(o)
B
filtered = orders
if status:
  filtered = [o for o in orders if o['status'] == status]
if min_total:
  filtered = [o for o in orders if o['total'] &gt;= min_total]
if max_total:
  filtered = [o for o in orders if o['total'] &lt;= max_total]
C
filtered = orders
if status:
  filtered = [o for o in filtered if o['status'] == status]
if min_total:
  filtered = [o for o in filtered if o['total'] &gt;= min_total]
if max_total:
  filtered = [o for o in filtered if o['total'] &lt;= max_total]
D
filtered = orders
if status:
  filtered = [o for o in filtered if o['status'] != status]
if min_total:
  filtered = [o for o in filtered if o['total'] &lt; min_total]
if max_total:
  filtered = [o for o in filtered if o['total'] &gt; max_total]
Attempts:
2 left
💡 Hint
Apply filters step by step on the current filtered list.

Practice

(1/5)
1. What does adding multiple filter parameters in a REST API URL do?
example.com/api/items?color=red&size=medium
easy
A. Returns items that match all filter conditions (color red AND size medium).
B. Returns items that match any one of the filter conditions (color red OR size medium).
C. Returns all items ignoring the filters.
D. Returns an error because multiple filters are not allowed.

Solution

  1. Step 1: Understand multiple filters in URL

    Multiple filters joined by & mean the server should apply all conditions together.
  2. Step 2: Interpret the example URL

    The URL ?color=red&size=medium means items must be red AND medium size.
  3. Final Answer:

    Returns items that match all filter conditions (color red AND size medium). -> Option A
  4. Quick Check:

    Multiple filters = AND condition [OK]
Hint: Multiple filters joined by & mean AND condition [OK]
Common Mistakes:
  • Thinking filters work as OR instead of AND
  • Assuming filters are ignored
  • Believing multiple filters cause errors
2. Which of the following is the correct syntax to filter items by category=books and author=doe in a REST API URL?
easy
A. example.com/api/items?category=books;author=doe
B. example.com/api/items?category=books&author=doe
C. example.com/api/items?category=books|author=doe
D. example.com/api/items?category=books author=doe

Solution

  1. Step 1: Identify correct separator for multiple filters

    In URLs, multiple query parameters are separated by &.
  2. Step 2: Check each option

    Only example.com/api/items?category=books&author=doe uses & correctly between filters.
  3. Final Answer:

    example.com/api/items?category=books&author=doe -> Option B
  4. Quick Check:

    Use & to separate filters [OK]
Hint: Use & to separate multiple filters in URL [OK]
Common Mistakes:
  • Using | or ; instead of &
  • Leaving spaces between parameters
  • Not using any separator
3. Given the REST API call:
GET /products?color=blue&size=large&in_stock=true
What kind of products will the server return?
medium
A. Products that are blue AND large AND in stock.
B. Products that are blue OR large OR in stock.
C. Products that are either blue or large, ignoring stock status.
D. All products regardless of filters.

Solution

  1. Step 1: Understand multiple filters joined by &

    Filters combined with & mean all conditions must be true together.
  2. Step 2: Apply to given filters

    Only products that are blue, large, and in stock will be returned.
  3. Final Answer:

    Products that are blue AND large AND in stock. -> Option A
  4. Quick Check:

    Multiple filters = AND condition [OK]
Hint: Multiple filters joined by & mean AND condition [OK]
Common Mistakes:
  • Thinking filters combine with OR
  • Ignoring some filters
  • Assuming filters are optional
4. You wrote this URL to filter users by age=30 and active=true:
example.com/api/users?age=30&active=true&
But the server returns an error. What is the likely problem?
medium
A. The URL should use commas instead of &.
B. The server does not support filtering by age.
C. The filter values must be in quotes.
D. The trailing & at the end causes a syntax error.

Solution

  1. Step 1: Check URL syntax for filters

    A trailing & at the end of query parameters is invalid syntax.
  2. Step 2: Understand server error cause

    The server likely rejects the URL because of the extra & with no following parameter.
  3. Final Answer:

    The trailing & at the end causes a syntax error. -> Option D
  4. Quick Check:

    Trailing & causes error [OK]
Hint: Avoid trailing & in URL query parameters [OK]
Common Mistakes:
  • Leaving trailing & at end of URL
  • Using commas instead of &
  • Assuming quotes are needed around values
5. You want to get all orders from the REST API where status is shipped and total is greater than 100. The API supports filtering by multiple parameters but only exact matches. How can you combine filters to get orders with status=shipped and total>100?
hard
A. Use ?status=shipped&total=100 and filter results manually.
B. Use ?status=shipped&total=gt:100 to specify greater than.
C. Use ?status=shipped&total_min=101 if the API supports range filters.
D. Use ?status=shipped&total>100 directly in URL.

Solution

  1. Step 1: Understand API filter limitations

    The API only supports exact matches, so direct > operator is not allowed.
  2. Step 2: Use API-supported range filter parameter

    Many APIs use parameters like total_min to filter values greater than a number.
  3. Step 3: Combine filters correctly

    Using ?status=shipped&total_min=101 filters orders with status shipped and total greater than 100.
  4. Final Answer:

    Use ?status=shipped&total_min=101 if the API supports range filters. -> Option C
  5. Quick Check:

    Use API range params for > filters [OK]
Hint: Use API-specific range filters like total_min for > conditions [OK]
Common Mistakes:
  • Trying to use > directly in URL
  • Assuming all APIs support gt: syntax
  • Filtering manually after fetching all data
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard