Which HTTP status code is the standard response for a successful REST API POST request that creates a new resource?
- A.200 OK
- B.201 Created, with a Location header pointing to the new resource
- C.204 No Content
- D.202 Accepted
Why B is correct
201 Created is the semantically correct response for a successful POST that created a resource. The Location header in the response should point to the new resource's URL. 200 OK is for successful responses that return data but didn't create a new resource. 204 No Content means success with no response body (often used for DELETE or PUT with no body). 202 Accepted means the request was received but processing hasn't completed yet.
Know someone studying for Web App Fundamentals? Send them this one.