Responses

In a REST API, HTTP responses are how the server communicates the result of a client’s request. Each response contains a status code, headers, and optionally, a body.

The status code informs the client of the outcome—whether the request was successful, resulted in an error, or requires further action. REST APIs should rely on standard HTTP status codes to signal success (2xx), client errors (4xx), and server errors (5xx).

The headers provide additional information like content type or caching details about the body.

The response body (if present) should include the data requested by the client, such as JSON or XML objects, plus error messages, or other relevant information indicating the outcome of the request.

Clear and consistent HTTP responses are critical for ensuring that clients can correctly interpret and respond to the server’s feedback.

See also: HTTP Status Codes and Retry