A successful POST /users that creates a user should ideally return…
Options
- 200 OK with an empty body and no extra headers
- 201 Created with a
Locationheader for the new resource (Correct option) - 204 No Content with no body and no headers
- 302 Found with a redirect to the list of users
Answer
201 Created with a Location header pointing to the new resource
Why
201 Created tells the client precisely that something new was created.
The Location header gives the URL of the new resource (e.g. /users/42), and the body usually contains the created user.
200 means generic success; 204 means success with no body (common for DELETE).
Remember
Created something → 201 + Location.