Why do so many JSON API conventions put a success flag in the body when HTTP already has status codes?
Reading around for a standard response shape, the recurring recommendation is an envelope containing a boolean success field, then either data or an error object.
This seems redundant. HTTP already carries that information in the status line, and it carries it in a place every client, proxy and cache understands without parsing anything.
So what is the reasoning? I am prepared to believe there is one, since the convention is very widespread, but every article I find asserts the shape without justifying it.
@architect_ayla · 2w ago
The cost of the envelope is worth stating, because it is real and it accumulates.
You lose the layers between you and the client. Caches, proxies, load balancers, monitoring, retry logic and alerting all understand status codes and none of them can read your body. A service returning 200 for everything looks perfectly healthy on every dashboard while failing every request.
That last one bites eventually. I have watched an outage last far longer than it should have because the error rate graph was flat.
The position I have settled on is a middle one and it is fairly common in practice:
That keeps the infrastructure informed and keeps domain semantics out of a four-hundred-code vocabulary that was never designed for them.
Reply
Report