What Is This?
The HTTP 201 Created status code indicates that the request has succeeded and a new resource has been created. It is typically returned after POST or PUT requests that create new resources. The response should include a Location header pointing to the URL of the newly created resource.
Common Causes & Solutions
Common Cause
Successful POST request creating a new database record
Common Cause
Successful PUT request creating a new resource at a specific URL
Common Cause
File upload completion creating a new file resource
Always include Location header
The Location header tells the client where the new resource can be accessed. Include the full URL or absolute path to the resource.
HTTP/1.1 201 Created
Location: /api/users/123
Content-Type: application/json
{
"success": true,
"data": {
"id": 123,
"name": "Jane Doe",
"createdAt": "2024-01-15T10:30:00Z"
}
}Related Entries
More from this reference:
Frequently Asked Questions
Should I return the created object in the response body?
Yes. While the Location header provides the URL, including the full created object in the response body saves the client an additional GET request and follows REST best practices.
Is 201 only for POST requests?
No. Both POST and PUT can return 201 Created. POST creates a sub-resource (server assigns the URL), while PUT creates or replaces a resource at a specific URL the client specifies.