HTTP status message in REST API

In a REST API, an HTTP status message is a three-digit code returned in the response header that indicates the outcome of the requested operation.

The first digit of the code indicates the class of response and the last two digits indicate a specific status within that class.

Some common HTTP status codes used in REST APIs include:

  • 200 OK: The request was successful and the requested data is included in the response.
  • 201 Created: The request was successful and a new resource was created as a result.
  • 204 No Content: The request was successful, but there is no additional information to send back, usually used for DELETE methods.
  • 400 Bad Request: The request was malformed or invalid.
  • 401 Unauthorized: The request requires authentication.
  • 403 Forbidden: The client is not authorized to access the requested resource.
  • 404 Not Found: The requested resource could not be found.
  • 500 Internal Server Error: An error occurred on the server while processing the request.

These status codes provide a standardized way for the API to communicate the outcome of the request to the client, allowing the client to determine if the request was successful and take appropriate action.

Additionally, the API can provide additional information about the error or the status of the request by sending a payload in the response body with more details about the status code.