Consider a REST API where a client sends a GET request to retrieve data. Which HTTP status code should the server return to indicate success?
Think about the difference between retrieving existing data and creating new data.
200 OK is the standard response for successful GET requests where data is retrieved without creating anything new.
When a client sends a POST request to create a new resource, which HTTP status code should the server return to indicate the resource was created successfully?
This status code means something new was made.
201 Created means the server successfully created a new resource in response to the POST request.
Explain why it is better REST practice for a POST request that creates a resource to return 201 Created rather than 200 OK.
Think about the meaning of each status code and what information it conveys to the client.
201 Created clearly tells the client that a new resource was made, which is more informative than the generic 200 OK.
A client sends a POST request to create a new user. The server creates the user and returns a response with a Location header pointing to the new user URL. What is the expected status code and typical response body?
Think about what 201 Created means and what the Location header is for.
201 Created with a Location header and a body containing the new resource details is the standard RESTful response after creating a resource.
A client sends a POST request to create a resource, but the resource already exists with the same data. What is the best RESTful status code and response behavior?
Think about how to inform the client that the resource already exists and cannot be duplicated.
409 Conflict is the correct status to indicate the request conflicts with the current state of the server, such as duplicate resource creation.