Rest API HTTP Response and Request Codes

HTTP Status codes are standard codes and refer to the predefined status of tasks done at the server. For example, HTTP Status 404 states that the requested resource is not present on the server.

Below are some of the commonly used HTTP Status Codes in REST API.

Status CodeMessageDetails
200OKIt shows success.
201CREATEDwhen a resource is successfully created
using POST or PUT requests. Return link
to a newly created resources using
location header.
204NO
CONTENT
when the response body is empty for
example, a DELETE request.
304NOT
MODIFIED
It used to reduce network bandwidth
usage in case of conditional GET
requests. The response body should be
empty. Headers should have dates,
location etc.
400BAD
REQUEST
It states that invalid input is provided, e.g.
validation error, missing data. The
request URI does not match the APIs in
the system or the operation failed for
unknown reasons. Invalid headers can
also, cause this error.
401UNAUTHORIZED OR
FORBIDDEN
It states that the user is not having access to
the method being used, for example,
delete access without admin rights.
The user is not authorized to use the API
403FORBIDDENThe requested operation is not
permitted for the user. This error can
also, be caused by ACL failures,
or business rule or data policy
constraints.
404NOT
FOUND
It states that the method is not available.
The requested resource was not found.
This can be caused by an ACL constraint
or if the resource does not exist.
405METHOD
NOT
ALLOWED
The HTTP action is not allowed for the
requested REST API, or it is not
supported by any API.
409CONFLICTstates conflict situation while executing the method.
for example, adding duplicate entries.
500INTERNAL
SERVER
ERROR
It states that the server has thrown some
exception while executing the method.

Components of an HTTP Request

ComponentsDescriptionExamples
VerbIdentifies the operation/HTTP Methods to be performed on the resourceGET, POST, DELETE, PUT etc.
Uniform Resource Identifier(URI)Used to identify the resource on the server.Example URI
HTTP VersionIndicate HTTP versionfor example, HTTP v1.1
Request HeaderContains metadata for the HTTP Request message as key-value pairs.For example, client ( or browser) type, format supported by the client, the format of the message body, cache settings, etc.
Request BodyMessage content or Resource representation{“firstName”:”Nitendra”,”lastName”:”Gautam”}

Components of an HTTP Response

ComponentsDescriptionExamples
Status or Response CodeIndicate Server status for the requested resource404, 200
HTTP VersionIndicate HTTP versionfor example HTTP v1.1
Response HeaderContains metadata for the HTTP Response message as key-value pairscontent length, content type, response date, server type etc.
Response BodyResponse message content or Resource representation{"status":"success"}