Every JSON endpoint applies the same body gate, and reports its refusals
A caller does not have to learn which endpoint bounds its input. Every endpoint that takes a JSON body applies the same limits and gives the same answer when they are exceeded.
The rule
- Every endpoint that accepts a JSON request body MUST apply the same body gate: the same media type, size, depth and top-level shape checks, refused the same way.
- A refusal from that gate MUST reach the caller with the status STORE-1 gives it: 415, 413, 400 or 422, and the error code STORE-1 pairs with that status.
- An implementation MUST NOT report it as a server error.
- A body is absent when a request sends zero-length content to an endpoint whose body is optional.
- An absent body MUST be mapped to an empty object ahead of the gate, whatever
Content-Typethe request carries. - Everything else MUST go through the gate.
- Optional never means unvalidated.
What it means
An endpoint that takes a JSON request body runs a gate before it reads a single field. The gate is the check every such endpoint runs: is the body sent as JSON, is it within the size bound, is it JSON at all and nested no deeper than the depth bound, and is its top level a shape the endpoint can work with. The rule does not fix the bounds; it fixes that there is one gate, that every endpoint runs the same one, and that an implementation cannot make an exception for one route because that route "never gets big bodies".
Two consequences carry most of the weight.
A gate refusal is a client error, never a 500. The gate refuses because of what
the caller sent, so the answer is the caller's to act on, and its status says which
kind of problem it was. STORE-1 gives each check its status, by the one test in the
conventions: the wrong media type is 415, a body too large is 413, a body from
which no JSON value could be read within the limits is 400, and a value that was
read but has the wrong shape is 422, each with the error code STORE-1 pairs with
it. An implementation that lets the refusal fall
through a general failure handler and surface as a server error has told the caller
the wrong thing, and made the two indistinguishable. API-7 says why that matters in
general; this rule is the specific case where the endpoint already knows the answer.
Optional is a statement about presence, not about checking. Where an endpoint's
body is optional, an absent body (zero-length content) is read as {} before the
gate, whatever Content-Type came with it, and the gate then runs on that. A body
that is present goes through the gate whether or not the endpoint needed it. So a
malformed body on an optional-body endpoint is refused, not quietly treated as
absent. Only where a body is required is zero-length content an empty body, refused
with 400.
Example
The same three bodies, sent as application/json to any JSON endpoint, get the same
three answers. The gate answers before any workflow-level meaning is read, so the
endpoint's own rules never see the first two.
POST /api/flowdrop/workflows
{"name":POST /api/flowdrop/workflows
"just a string"POST /api/flowdrop/workflows
{"name": "WF"}The last body, sent with Content-Type: text/plain, is refused with 415 before
any of this is looked at. Whatever the endpoint refuses from here on (STORE-2, say)
is a refusal of the workflow, and the gate has nothing further to say.