0
0
Rest APIprogramming~30 mins

Human-readable error messages in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Human-readable error messages
📖 Scenario: You are building a simple REST API that returns data about books. When something goes wrong, you want to send clear, easy-to-understand error messages to the user instead of confusing technical errors.
🎯 Goal: Create a small API simulation that returns human-readable error messages for common problems like missing data or invalid input.
📋 What You'll Learn
Create a dictionary called books with three book entries and their authors
Create a variable called requested_book with the name of the book to search
Write code to check if requested_book is in books and handle errors with clear messages
Print the result or the error message
💡 Why This Matters
🌍 Real World
APIs often need to tell users what went wrong in a way they can understand, instead of showing confusing technical errors.
💼 Career
Clear error messages improve user experience and are important for developers working on web services and APIs.
Progress0 / 4 steps
1
Create the books data
Create a dictionary called books with these exact entries: '1984': 'George Orwell', 'To Kill a Mockingbird': 'Harper Lee', 'The Great Gatsby': 'F. Scott Fitzgerald'
Rest API
Need a hint?

Use curly braces {} to create a dictionary with the exact book titles as keys and authors as values.

2
Set the requested book
Create a variable called requested_book and set it to the string 'The Catcher in the Rye'
Rest API
Need a hint?

Assign the exact string 'The Catcher in the Rye' to the variable requested_book.

3
Check for the book and prepare error messages
Write an if statement to check if requested_book is in books. If it is, create a variable result with the message "Found: {requested_book} by {author}". If not, set result to the error message "Error: '{requested_book}' not found in the library."
Rest API
Need a hint?

Use an if statement to check membership and f-strings to create clear messages.

4
Print the result
Write a print statement to display the variable result
Rest API
Need a hint?

Use print(result) to show the message on the screen.