Consider this REST API call:
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
{"name": "Alice"}What is the main intent of the POST method here?
Think about what POST usually does in REST APIs.
The POST method is used to create new resources on the server. Here, sending user data means the client wants to add a new user.
Which statement best explains why the GET HTTP method is considered both safe and idempotent?
Think about what 'safe' and 'idempotent' mean in HTTP.
GET is safe because it does not change data on the server. It is idempotent because making the same GET request multiple times results in the same server state.
Given this HTTP DELETE request to remove a user:
DELETE /users/123 HTTP/1.1 Host: example.com
The server successfully deletes the user. What is the most appropriate HTTP status code the server should return?
Think about what status code means success with no content returned.
204 No Content means the request was successful but there is no content to return, which fits a successful DELETE.
A client wants to update a user's email but uses this HTTP request:
POST /users/123 HTTP/1.1
Host: example.com
Content-Type: application/json
{"email": "new@example.com"}Why is this a misuse of HTTP methods?
Consider which HTTP methods are intended for updating resources.
POST is generally for creating resources. Updating existing resources should use PUT or PATCH to clearly express intent.
You want to change only the phone number of a user resource without affecting other fields. Which HTTP method best expresses this intent?
Think about which method is designed for partial updates.
PATCH is used for partial updates to a resource, changing only specified fields without replacing the entire resource.