HTTP 200 OK vs 201 Created
Both 200 and 201 are success codes, but they convey different semantics. A 200 means the request succeeded in general, while a 201 specifically means a new resource was created. Using the correct code helps API consumers understand what happened without inspecting the response body.
Description
The request succeeded. The meaning depends on the HTTP method: GET returns the resource, POST reports the action result, HEAD returns headers only.
When You See It
The most common HTTP response — indicates the request was processed successfully.
How to Fix
No fix needed. The request succeeded as expected.
Description
The request succeeded and a new resource was created. Typically returned after POST or PUT requests that create a new entity.
When You See It
After successfully creating a new user, post, order, or other resource via a REST API.
How to Fix
No fix needed. Check the Location header for the URL of the new resource.
Key Differences
200 is a general success — the request was processed and the response body contains the result.
201 specifically means a new resource was created as a result of the request.
201 should include a Location header pointing to the newly created resource's URL.
200 is appropriate for GET, PUT (update), and DELETE operations.
201 is appropriate for POST (create) and sometimes PUT (create if not exists) operations.
When to Use Which
Return 200 for successful GET requests, updates (PUT/PATCH), deletions (DELETE), and general operations. Return 201 for successful POST or PUT requests that create a new resource, and include a Location header with the URL of the new resource. This distinction makes APIs self-documenting and helps clients handle responses correctly.