0
0
Rest APIprogramming~30 mins

Resource-based design thinking in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Resource-based Design Thinking with REST API
📖 Scenario: You are building a simple REST API for a library system. The system manages books as resources. Each book has a unique ID, a title, and an author.We will create the data structure for books, configure a filter for books by author, implement the core logic to select books by that author, and finally output the filtered list.
🎯 Goal: Build a REST API endpoint that returns a list of books filtered by a given author using resource-based design thinking.
📋 What You'll Learn
Create a dictionary called books with book IDs as keys and dictionaries with title and author as values
Create a variable called filter_author to hold the author name to filter by
Use a dictionary comprehension to create filtered_books containing only books by filter_author
Print the filtered_books dictionary as the output
💡 Why This Matters
🌍 Real World
Filtering resources by attributes is a common task in REST APIs, such as listing books by author or products by category.
💼 Career
Understanding resource-based design thinking and filtering is essential for backend developers building APIs that serve dynamic data based on client requests.
Progress0 / 4 steps
1
DATA SETUP: Create the books dictionary
Create a dictionary called books with these exact entries: 1: {'title': 'The Hobbit', 'author': 'J.R.R. Tolkien'}, 2: {'title': '1984', 'author': 'George Orwell'}, 3: {'title': 'The Silmarillion', 'author': 'J.R.R. Tolkien'}
Rest API
Need a hint?
Remember to use the exact keys and values as shown, with book IDs as keys and dictionaries as values.
2
CONFIGURATION: Set the filter author
Create a variable called filter_author and set it to the string 'J.R.R. Tolkien' to filter books by this author
Rest API
Need a hint?
Make sure the variable name is exactly filter_author and the value is the exact string.
3
CORE LOGIC: Filter books by author
Use a dictionary comprehension to create a new dictionary called filtered_books that contains only the books from books where the author matches filter_author
Rest API
Need a hint?
Use a dictionary comprehension with the condition to check the author matches filter_author.
4
OUTPUT: Print the filtered books
Write a print statement to display the filtered_books dictionary
Rest API
Need a hint?
Use print(filtered_books) to show the filtered dictionary.