Error Response Format in REST API
📖 Scenario: You are building a simple REST API that returns error messages in a consistent format when something goes wrong.
🎯 Goal: Create a Python dictionary that represents an error response with a code and message, then print it as JSON.
📋 What You'll Learn
Create a dictionary called
error_response with keys code and messageSet
code to 404 and message to "Resource not found"Use the
json module to convert the dictionary to a JSON stringPrint the JSON string
💡 Why This Matters
🌍 Real World
APIs often need to send error messages in a clear, consistent format so clients can understand what went wrong.
💼 Career
Knowing how to format error responses is important for backend developers and anyone working with web services.
Progress0 / 4 steps