Sobes.tech
Junior — Middle

Which HTTP requests should have the property of idempotency?

sobes.tech AI

Answer from AI

Idempotence in HTTP means that performing the same request multiple times will not change the server's state after the first execution.

HTTP methods that should be idempotent include:

  • GET — retrieving a resource should not change the server's state.
  • PUT — updating a resource should lead to the same result on repeated requests.
  • DELETE — deleting a resource should be idempotent; repeated deletion of the same resource should not cause errors or changes.
  • HEAD — similar to GET but without the response body, also idempotent.

The POST method is not idempotent, as it is usually used to create new resources, and repeated requests may lead to duplicates.

Example:

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

{"name": "Ivan"}

Repeating this request will update the user with id 123 identically, without creating new records.

Which HTTP requests should have the property of… - sobes.tech