Sobes.tech
Intern

Milline HTTP-meetod, vastavalt spetsifikatsioonile, kasutatakse ressursi täielikuks asendamiseks ja on idempotent? PATCH POST PUT DELETE

sobes.tech AI

Vastus AI-lt

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, not idempotent.
  • DELETE — deletes the resource, also idempotent, but does not replace it.

Example of using PUT:

PUT /users/123 HTTP/1.1
Content-Type: application/json

{"name": "Иван", "age": 30}

This request will replace the data of the user with ID 123 with new data.