0
0
Rest APIprogramming~15 mins

Why status codes communicate outcomes in Rest API - See It in Action

Choose your learning style9 modes available
Why Status Codes Communicate Outcomes
📖 Scenario: You are building a simple web API that returns different status codes to show if a request was successful or if there was an error. Status codes help the client understand what happened after they asked for something.
🎯 Goal: Create a small program that simulates API responses with status codes and messages. You will set up data for responses, configure a status code to check, write logic to pick the right message based on the code, and finally print the result.
📋 What You'll Learn
Create a dictionary called responses with exact status codes as keys and their messages as values
Create a variable called status_code and set it to an exact integer value
Write code to get the message from responses using status_code
Print the message exactly as retrieved from the dictionary
💡 Why This Matters
🌍 Real World
APIs use status codes to tell clients if their request worked or if there was a problem. This helps apps and websites handle responses correctly.
💼 Career
Understanding status codes is important for backend developers, API designers, and anyone working with web services to communicate clearly with clients.
Progress0 / 4 steps
1
Create the API response messages dictionary
Create a dictionary called responses with these exact entries: 200: 'OK', 404: 'Not Found', 500: 'Internal Server Error'
Rest API
Need a hint?

Use curly braces {} to create a dictionary with numbers as keys and strings as values.

2
Set the status code to check
Create a variable called status_code and set it to the integer 404
Rest API
Need a hint?

Just assign the number 404 to the variable status_code.

3
Get the message for the status code
Create a variable called message and set it to the value from responses using the key status_code
Rest API
Need a hint?

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

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

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