Mid-LevelAPI & Integration Testing
How do you test idempotency in API endpoints?
- idempotency
- duplicate requests
- data integrity
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Idempotent operations should produce the same result when called multiple times. Tests: (1) POST with same idempotency key twice, verify 200 (not 201) on second call and same response body. (2) Verify database state has only one record. (3) Test expired idempotency keys. (4) Test with different payloads but same key, should return error or original result. (5) PUT and DELETE should be naturally idempotent. (6) Concurrent requests with same key should not create duplicates. Common mistake: testing only the response, not the side effects.
What interviewers listen for
- Schema-first thinkingYou validate response shape before you assert on values, every time.
- Status-code literacyYou can defend why 401 vs 403 vs 422 matters for the consumer.
- Contract awarenessYou know when consumer-driven contract tests beat end-to-end checks.
- Auth fluencyYou can describe rotating tokens across parallel workers without secrets in logs.