Junior — Middle
Explain what the PUT method means in the context of HTTP requests.
sobes.tech AI
Answer from AI
The PUT method in HTTP is used to replace or create a resource at the specified URL. If the resource exists, PUT completely updates it; if not, it creates a new one with the given data.
Main features of PUT:
- Idempotency: repeated requests with the same data do not change the result after the first call.
- Full update: usually, all resource data is sent, not just changed fields.
Example: if you have a user resource at /users/123, a PUT request with a new JSON object will completely replace the user's data.
PUT /users/123 HTTP/1.1
Content-Type: application/json
{
"name": "Ivan",
"email": "ivan@example.com"
}
Unlike PATCH, which is intended for partial updates, PUT requires sending the full set of data.