0
0
Rest APIprogramming~30 mins

Multiple filter parameters in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple Filter Parameters in REST API
📖 Scenario: You are building a simple REST API for a bookstore. Customers want to search for books by different filters like author and genre.
🎯 Goal: Create a REST API endpoint that accepts multiple filter parameters and returns the matching books.
📋 What You'll Learn
Create a list of books with title, author, and genre
Add variables to hold filter parameters for author and genre
Filter the list of books based on the given author and genre
Return the filtered list as JSON output
💡 Why This Matters
🌍 Real World
Filtering data by multiple parameters is common in search features on websites and apps, like searching for products by brand and category.
💼 Career
Understanding how to handle multiple filter parameters is important for backend developers building APIs that serve filtered data to frontend applications.
Progress0 / 4 steps
1
Create the initial data set
Create a list called books with these exact dictionaries: {'title': 'The Hobbit', 'author': 'Tolkien', 'genre': 'Fantasy'}, {'title': '1984', 'author': 'Orwell', 'genre': 'Dystopian'}, and {'title': 'The Silmarillion', 'author': 'Tolkien', 'genre': 'Fantasy'}.
Rest API
Need a hint?

Use a list of dictionaries to store the books with their details.

2
Add filter parameters
Create two variables called filter_author and filter_genre. Set filter_author to 'Tolkien' and filter_genre to 'Fantasy'.
Rest API
Need a hint?

Set the filter variables to the exact strings given.

3
Filter the books list
Create a new list called filtered_books that contains only the books where author equals filter_author and genre equals filter_genre. Use a list comprehension.
Rest API
Need a hint?

Use a list comprehension with an if condition checking both author and genre.

4
Print the filtered books
Print the filtered_books list.
Rest API
Need a hint?

Use print(filtered_books) to show the filtered list.