0
0
Rest APIprogramming~30 mins

Search parameter in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Search Parameter in REST API
📖 Scenario: You are building a simple REST API for a bookstore. Customers want to search for books by their title.
🎯 Goal: Create a REST API endpoint that accepts a search parameter called title and returns books matching that title.
📋 What You'll Learn
Create a list of books with exact titles and authors
Add a search parameter variable called search_title
Filter the list of books to only those whose title contains search_title
Print the filtered list of books as the output
💡 Why This Matters
🌍 Real World
Searching books by title is a common feature in online bookstores and library systems.
💼 Career
Understanding how to filter data based on search parameters is essential for backend developers building APIs.
Progress0 / 4 steps
1
Create the initial data structure
Create a list called books with these exact dictionaries: {'title': 'Python Basics', 'author': 'John Doe'}, {'title': 'Advanced Python', 'author': 'Jane Smith'}, and {'title': 'Learning REST APIs', 'author': 'Alice Brown'}.
Rest API
Need a hint?

Use a list of dictionaries with keys 'title' and 'author'.

2
Add the search parameter
Create a variable called search_title and set it to the string 'Python'.
Rest API
Need a hint?

Set search_title exactly to 'Python'.

3
Filter books by search parameter
Create a list called filtered_books that contains only the books from books where the title contains the string in search_title. Use a list comprehension with book['title'] and search_title.
Rest API
Need a hint?

Use a list comprehension with if search_title in book['title'].

4
Print the filtered books
Print the variable filtered_books to display the books matching the search parameter.
Rest API
Need a hint?

Use print(filtered_books) to show the result.