What is the purpose of HTTP status code 200 vs. 201, and when does a server return each?
- A.200 (OK): the request was successful and the response body contains the requested resource (used for GET requests and successful general responses). 201 (Created): the request was successful and a new resource was created as a result (returned after a successful HTTP POST or PUT that creates a new record -- the response typically includes the Location header with the URL of the new resource)
- B.200 means the server is overloaded; 201 means the request was successful
- C.200 is for HTTP/1.0 responses; 201 is for HTTP/2 responses
- D.200 means the page was cached; 201 means the page was freshly fetched from the server
Why A is correct
HTTP status codes (RFC 7231): 2xx = Success. 200 OK: standard success response; the response body contains the requested content. Used for: GET (resource returned), DELETE success, generic success. 201 Created: a new resource was created; commonly returned by POST or PUT operations on a REST API. The 'Location' header points to the newly created resource URL. Other important 2xx: 204 No Content (success but no body, e.g., DELETE), 206 Partial Content (range requests for video streaming). None of the options A, C, D correctly describe 200 vs 201.
Know someone studying for Network Fundamentals? Send them this one.