Intern
Which HTTP method, according to the specification, is used for full resource replacement and is idempotent? PATCH POST PUT DELETE
sobes.tech AI
Answer from AI
According to the HTTP specification, the PUT method is used for completely replacing a resource and is idempotent. This means that repeated PUT requests with the same data will not change the resource's state after the first request.
- PUT — replaces the entire resource.
- PATCH — partially updates the resource.
- POST — usually creates a new resource or performs an action, and is not idempotent.
- DELETE — deletes the resource, is also idempotent, but does not replace.
Example of using PUT:
PUT /users/123 HTTP/1.1
Content-Type: application/json
{"name": "Ivan", "age": 30}
This request will replace the data of the user with ID 123 with new data.