Skip to the page

Designing HTTP APIs · mid

One error format: RFC 9457 problem details

RFC 9457 (July 2023, replacing RFC 7807) defines a standard JSON error body, served as application/problem+json, with type, title, status, detail and instance fields plus your own extension fields, so every client can handle errors the same way.

The notes

What you must know

  • Members: type (a URI that identifies the problem kind; 'about:blank' means 'just the HTTP status'), title (short, stable summary), status (same as the HTTP status), detail (this occurrence, human readable), instance (a URI for this occurrence, e.g. the request id).
  • Extensions are allowed, e.g. errors: [{ field, message }] for validation, balance for a payment problem. Clients must ignore extensions they do not know.
  • Clients should switch on type (stable), not parse detail (for humans).
  • Several problems of different kinds: report the most important one; several occurrences of one kind (many invalid fields) go in an extension array.
  • Never leak internals (stack traces, SQL, hostnames) in detail; log them with the request id instead.
  • Media type: application/problem+json. RFC 9457 obsoletes RFC 7807, so mention 9457 in interviews.

The red pen

Common traps: mistake → fix

  • Mistake: Every team can invent its own error JSON

    Fix: clients then need special cases per endpoint; one standard shape scales.

  • Mistake: detail is for machines

    Fix: detail is for humans; machines use type and status.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does your API return when something fails?
  2. Have you heard of problem details (RFC 9457/7807)? What are its fields?
  3. How do you return several validation errors at once?
  4. How does a frontend show friendly messages from it?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview