201 Created
The HTTP 201 status code means a request was successful, and a new resource has been created.
201 Created
status code is commonly used as a response to POST and PUT requests that create new resources. For example, if you interact with a billing API, 201 is an appropriate code if your request creates a new subscription.
With PUT requests, you specify the new location yourself, while with POST requests, the server takes care of it.
POST /websites
Content-Type: application/json
In response to POST requests, the server will also include a Location
header containing the URL of a newly created resource:
HTTP/2 201 Created
Location: /websites/42
201 vs 200
Both 200 and 201 status codes signal that the resource was successfully created.
The only difference is that with 200 OK
, you would return the resource in the response body (for requests that create a resource), while with 201, only the reference would be sufficient.