Sobes.tech
Middle+

What is idempotency? Explain in simple words. Which HTTP methods are idempotent, and which are not?

sobes.tech AI

Answer from AI

Idempotence is a property of an operation where multiple executions produce the same result as a single execution.

In simple words: if you press a button multiple times, the system's state will not change after the first press.

In HTTP:

  • Idempotent methods include GET, PUT, DELETE, HEAD, OPTIONS, TRACE.

    • For example, PUT updates a resource, and a repeated PUT with the same data will not change the state.
    • DELETE removes a resource, and a repeated DELETE will not change the result.
  • The POST method is not idempotent, as each call can create a new resource or change the state differently.

Example: if you send a PUT request to update a user's profile, repeated requests with the same data will not further change the profile.