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?
Remember the filter is for category 'books' and price less than 20.
The filter selects only products where category is 'books' and price is less than 20. Only the first product matches both conditions.
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?
Look for the common convention using suffixes like '_gt' for greater than.
The common REST API convention uses suffixes like '_gt' to indicate 'greater than'. So 'age_gt=30' means age greater than 30.
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?
Think about how multiple query parameters combine filters.
Some APIs treat multiple query parameters as OR filters, so no item matches both filters simultaneously, resulting in empty results.
You want to filter records between two dates using query parameters. Which of the following is NOT a valid syntax?
Check which characters are allowed in URL query parameters without encoding.
The characters '>=' and '<=' are not valid in query parameter keys without encoding, so 'date>=...' is invalid syntax.
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?
Check each order against all three conditions carefully.
Only order with id 1 matches all filters: status 'shipped', total > 100, and date before 2024-01-01.