REST Response
Last updated
Was this helpful?
Last updated
Was this helpful?
A REST API should use an appropriate HTTP Status Code and Content Type when responding to a client's request.
An API can support multiple response content types. It's preferred to use a JSON content type by default. When an API supports multiple content types the client can specify the desired content type with the .
The following table shows a list of common content types:
Default. Content type for a JSON response body.
Content type for a XML response body. Should be used when the XML is unreadable by casual users.
Content type for a XML response body. Should be used when the XML is readable by casual users.
REST APIs should use the range of to give the clients the most appropriate result of the request processing.
An API should at least use the following HTTP Status Codes for corresponding HTTP methods:
200
OK
X
X
X
X
201
Created
X
202
Accepted
X
204
No Content
X
X
X
X
303
See Other
X
400
Bad Request
X
X
X
401
Unauthorized
X
X
X
X
X
403
Forbidden
X
X
X
X
X
404
Not Found
X
X
X
X
X
500
Server error
X
X
X
X
X
401
should be returned when client fails to authenticate.
403
should be returned when client is authenticated but does not have necessary permission to perform the operation.
404
should be returned when the static path of the request does not exist on the server.
GET
For retrieving a resource or a collection of resources.
200
should be returned on success. If a collection asked for is empty or user does not have permission to access it, 200
is still to be returned with and empty array.
204
should be returned when a single resource requested does not exist or the user does not have permission to access it.
POST
For creating a resource.
201
should be returned when the resource was created. The response body should contain the created resource.
202
should be returned when the request has been accepted for processing but may not have been acted upon or completed yet.
400
should be returned if the request is invalid, i.e. the resource already exists or contains invalid fields.
PUT
For updating a existing resource.
200
should be returned when resource is successfully updated with the updated resource in the response.
204
should be returned when the resource is not found or the user does not have permission to update it.
400
should be returned when the request is invalid, i.e. the resource contains invalid fields.
PATCH
For making a partial update on a resource.
200
should be returned when resource is successfully updated with the updated resource in the response.
204
should be returned when the resource is not found or the user does not have permission to update it.
400
should be returned when the request is invalid, i.e. the resource contains invalid fields.
DELETE
For removing a resource.
200
should be returned when the resource is deleted and there is a need for a content in the response.
204
should be returned when the resource is deleted, does not exist or the user does not have permission to delete it and there is no content in response.
Content type for the for 4xx
and 5xx
statuse codes.
500
should be returned when the server encounters some unexpected error, preferably along with an object.
303
should be returned if the resource already exists on the resource server. The response should contain the header with the URI of the existing resource.