Categories
API Quick Tips Quick Tips

Try a standard format for API error responses

< 1 min read

Are you tired of trying to figure out your own format for detailed API error responses? Consider leaning on the Problem Details for HTTP APIs specification.

Here is an example "problem details" error response:

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
Content-Language: en

{
    "type": "https://example.net/validation-error",
    "title": "Your request parameters didn't validate.",
    "invalid-params": [
        {
            "name": "age",
            "reason": "must be a positive integer"
        },
        {
            "name": "color",
            "reason": "must be 'green', 'red' or 'blue'"
        }
    ]
}

— Source: RFC 7807 – Problem Details for HTTP APIs

Learn more about how you can use problem details in my blog post Send awesome structured error responses with Express.

Original tweet

One reply on “Try a standard format for API error responses”

Comments are closed.