HTTP 201 Created — What It Means and How to Fix It
The HTTP 201 (Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. This is typically returned after a successful POST or PUT request that creates a new resource on the server.
Essential Reading: Designing Data-Intensive Applications
The system design bible for software engineers. Learn to build reliable, scalable, and maintainable systems.
Common Causes
- Successful creation of a new resource via a POST request (e.g., creating a new user, product, or document).
- Successful creation or update of a resource via a PUT request where the resource did not previously exist.
- A server-side process successfully generating a new resource based on the client's request.
Code Examples to Handle HTTP 201
curl -I https://httpbin.org/status/201
How to Fix It
- Verify the request method: Ensure a POST or PUT method was used, as 201 is not typically expected for GET or DELETE.
- Check the response body: The response body should ideally contain a representation of the newly created resource.
- Inspect the 'Location' header: The server should include a 'Location' header with a URI pointing to the newly created resource.
- Confirm idempotency (for PUT): If a PUT request resulted in 201, it implies the resource was created. Subsequent identical PUT requests to the same URI should ideally return 200 OK or 204 No Content if the resource already exists and is updated, not 201 again.
Related Status Codes
Frequently Asked Questions
What causes HTTP 201?
HTTP 201 is caused by a successful request (typically POST or PUT) that results in the creation of one or more new resources on the server. It signifies that the server has understood the request and successfully fulfilled the creation operation.
How do I fix HTTP 201?
HTTP 201 is generally a success code, so it doesn't need 'fixing' in the traditional sense. If you're receiving it unexpectedly, ensure your client-side logic correctly handles the creation of resources and expects this response. For server-side, ensure your API correctly returns 201 only when a new resource is genuinely created and includes the 'Location' header.