Sobes.tech
Junior — Middle

Can you give examples of HTTP requests that are idempotent?

sobes.tech AI

Answer from AI

Idempotent HTTP requests are those that do not change the server's state after the first call, even if they are repeated.

Examples of idempotent HTTP methods:

  • GET — retrieve a resource. Repeated requests do not modify data.
  • PUT — update a resource. Sending the same PUT multiple times results in the same state.
  • DELETE — delete a resource. Repeating DELETE on the same resource does not change the state (the resource is already deleted).
  • HEAD — similar to GET but without the response body, also idempotent.

Example:

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

{"name": "Ivan"}

Sending this request multiple times will result in the user with id 123 having the name "Ivan" — the state will not change after the first request.