HTTP Status 201 indicates that as a result of HTTP POST
request, one or more new resources have been successfully created on the server.
1. HTTP Headers
The response may contain URI in Location
header field in HTTP headers list, which can have reference to the newly created resource.
Also, the response payload also may include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate.
The entity format is specified by the media type given in the Content-Type
header field.
The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with
202 (Accepted)
response instead.
2. Lost update problem
HTTP 201
response MAY contain an ETag
response header field indicating the current value of the entity tag for the requested variant just created.
ETag
header field can be used in later conditional requests to prevent the “lost update” problem.
Lost update problem happens when multiple people edit a resource without knowledge of each others’ changes.
In this scenario, the last person to update a resource “wins”, and previous updates are lost. ETags can be used in combination with the If-Match
header to let the server decide if a resource should be updated. If ETag
does not match then server informs the client via a 412 (Precondition Failed)
response.
Reference: 201 (Created)