0
0
Rest APIprogramming~15 mins

Error codes for machine consumption in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Error Codes for Machine Consumption
📖 Scenario: You are building a simple REST API that returns error codes in a way machines can easily understand. This helps other programs know exactly what went wrong.
🎯 Goal: Create a small API response structure with error codes and messages that machines can read and use.
📋 What You'll Learn
Create a dictionary called error_codes with exact error code keys and message values
Create a variable called requested_code with a specific error code string
Use a dictionary lookup to get the error message for requested_code
Print the error message exactly as retrieved from the dictionary
💡 Why This Matters
🌍 Real World
APIs often send error codes and messages so other programs can understand what went wrong and respond correctly.
💼 Career
Knowing how to structure error responses is important for backend developers and anyone working with APIs.
Progress0 / 4 steps
1
Create the error codes dictionary
Create a dictionary called error_codes with these exact entries: '404': 'Not Found', '500': 'Internal Server Error', '403': 'Forbidden'
Rest API
Need a hint?

Use curly braces {} to create a dictionary with string keys and string values.

2
Set the requested error code
Create a variable called requested_code and set it to the string '404'
Rest API
Need a hint?

Assign the string '404' to the variable requested_code.

3
Lookup the error message
Create a variable called error_message and set it to the value from error_codes using the key requested_code
Rest API
Need a hint?

Use square brackets [] to get the value from the dictionary using the key.

4
Print the error message
Write a print statement to display the value of error_message
Rest API
Need a hint?

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