Structured Error Responses for an HTTP API
Problem details can give an API response a machine-readable problem type and useful human context under a documented format.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a rejected input
A response can include a status and a recognized problem type for an invalid quantity. A human description can explain a particular request's issue. Stable codes and messages show why clients should rely on structured fields.
Respect the HTTP boundary
The response status still conveys the HTTP outcome. Meaningful details should describe what the client can correct without exposing internal debug records. Review privacy in diagnostics.[1]
Preserve stable machine fields while giving humans context
A structured API error can describe an invalid date range using the problem details format. The response can supply a problem type identifier and a readable explanation. A client can branch on the documented stable type while displaying contextual detail. See error results and exceptions.
Status: 400 under this endpoint's contract
Media type: application/problem+json
Type identifies invalid date range
Detail explains which values conflict
Verify extensions and status against the published interface
Fields extending problem details can identify input locations if documented. Avoid exposing unrelated internal exception text or private data. Test two distinct failures that share the same HTTP status.