Reading the Parts of an HTTP Response
An HTTP response conveys status, field metadata, and sometimes content. Interpret the content under both the status and its representation metadata.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace two outcomes
A read can produce a successful response with a stored summary or a not-found response with an error description. Both may contain text or JSON. The status supplies context for the structured result.
Handle responses without content
Some response semantics omit content, such as a successful response with status 204. A parser expecting JSON on every result can fail on a valid empty response. Absence policies help define that case.[1]
Link a status line to the headers and body it describes
An HTTP/1.1 response can report status 200 and declare JSON content. The result is useful only if the actual body parses for the consumer and satisfies the expected fields. A successful status does not validate a domain schema. See structural and domain validation.
Status line: HTTP/1.1 200 OK
Content-Type: application/json
Body example: {"count":2}
Validate the JSON type and field after reading response framing
Test a response that intentionally has no message content
Certain statuses and request methods define special content rules. Test ordinary success, a no-content case and a structured application error. Keep version-specific framing in the HTTP client library.