When would you expect 200, 201, 202 and 204 from an HTTP API?
Answer
200 means the request succeeded and commonly returns a representation or operation result. 201 means one or more resources were created. 202 means the request was accepted but processing is not complete, which is common for asynchronous jobs. 204 means the operation succeeded and intentionally returns no response content. The correct choice depends on the endpoint contract and operation semantics, not on a blanket rule that every success is 200.
Strong answer includes
- 201 means created
- 202 is asynchronous/non-final acceptance
- 204 intentionally has no response content
Practical example
Deleting a resource returns 204 and an empty body, while creating the same resource returns 201 with a Location header. Both are successful responses but communicate different outcomes.