CodePark/ questions / Status codes
START PRACTICINGPRACTICE
Backend question · HTTP & API design › Status codes

POST /users creates a user with ID 57 synchronously. What is the most precise response?

201 Created with Location: /users/57

"201 Created with Location: /users/57" is the most precise. 201 Created says a new resource now exists. The Location header tells the client its URL. The body can also carry the new user.

"200 OK with the new user in the body" is not wrong, but it is less precise. It does not say that something was created. "202 Accepted with the new user in the body" is wrong, because 202 means the work is only queued, not done. "204 No Content" is wrong, because it says nothing about creation and sends no body.