Posted 12/05/2024

Problem Details for HTTP APIs

RFC 9457 - Problem Details for HTTP APIs. The document defines a “problem detail” to carry machine-readable details of errors in HTTP response content to avoid the need to define new error response formats for HTTP APIs.

Cheat Sheet

Members of a Problem Details Object

Media Types

JSON: application/problem+json XML: application/problem+xml

Extensibility

Custom properties can be added to the problem object but must follow naming conventions (e.g., start with a letter and use alphanumeric characters or _).

Best Practices

Use resolvable URIs for type and instance when possible. Avoid exposing sensitive details (e.g., stack traces) in error responses. Ensure title, status, and other fields provide clarity without requiring type dereferencing. Ensure proper validation of any additional fields.

Example

{
  "type": "https://example.com/probs/not-found",
  "title": "Resource Not Found",
  "status": 404,
  "detail": "The requested resource does not exist.",
  "instance": "/api/resource/123"
}