Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: universal
api-designresthttpheadersconsistency
Return resource data in the response body, not in custom headers
Headers are for transport/protocol metadata; do not stuff payload data such as counts, lists, or business values into custom response headers as a special case — put it in the response body where clients expect it.
PR: hegnar-shareholders-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | // payload data smuggled into a custom header |
| 2 | res.setHeader('X-Total-Count', String(total)); |
| 3 | res.setHeader('X-Item-Ids', ids.join(',')); |
| 4 | res.status(204).end(); // client must parse headers to get real data |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // data lives in the body, headers stay protocol metadata |
| 2 | res.status(200).json({ |
| 3 | total, |
| 4 | itemIds: ids, |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)