Answer
Idempotency in API
Idempotency refers to the property of an operation where applying the operation multiple times has the same effect as applying it once.
In API testing, idempotent methods ensure that performing the same request multiple times will not produce different outcomes beyond the initial request''s effect.
Idempotency by HTTP Method
| Method | Idempotent | Example |
|---|---|---|
| GET | Yes | Retrieving user info — same result every time |
| POST | No | Creating a user — creates a new record each time |
| PUT | Yes | Updating user info — same final state regardless |
| PATCH | No | Partial update — result may vary based on current state |
| DELETE | Yes | Deleting a user — resource deleted, subsequent calls have no effect |
Examples
GET — Idempotent: Yes
GET /api/users/123
Returns the same user data regardless of how many times called.
POST — Idempotent: No
POST /api/users
{ "name": "John" }
Each call creates a NEW user profile with a different ID.
PUT — Idempotent: Yes
PUT /api/users/123
{ "name": "Updated John" }
Repeating this always results in the same final state.
DELETE — Idempotent: Yes
DELETE /api/users/123
First call deletes the user. Subsequent calls return 404 — no additional effect.
Why This Matters
In case of network failures during API requests, idempotent methods ensure that retrying the request does not lead to unintended consequences such as duplicate resource creation or data corruption.
