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 an uptime monitoring API, 201 is an appropriate code if your request creates a new website.
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 enough.
No spyware, no promotional emails, or keyword-stuffed junk. I will only send you a single email when I've got something interesting to say. Unsubscribe anytime.
You can also subscribe to the Atom feed (it's like RSS, but better).