API Design interview question · Most asked
Which HTTP methods are safe and idempotent, and why does it matter?
Summary
Safe methods (GET, HEAD, OPTIONS) don't change state; idempotent methods (GET, HEAD, PUT, DELETE, OPTIONS) have the same effect whether called once or many times. POST and PATCH are not idempotent by default.
Longer Answer
Idempotency lets clients, proxies and SDKs retry safely after timeouts. Caches and crawlers assume GET is safe, so never change state on GET. Make POST retry-safe with idempotency keys.
Key Points
- Safe: no state change
- Idempotent: repeatable
- POST/PATCH need idempotency keys
- Never mutate on GET
Comparison / Tradeoffs
| Method | Safe | Idempotent |
|---|---|---|
| GET | Yes | Yes |
| PUT | No | Yes |
| DELETE | No | Yes |
| POST | No | No |
| PATCH | No | No (usually) |
More most-asked API Design questions
- What makes an API RESTful, and what are good REST design practices?
- Which HTTP status codes should an API use, and when?
- Compare offset pagination and cursor (keyset) pagination.
- How should you version an API?
- How do idempotency keys work for POST requests?
- When would you choose GraphQL over REST, or gRPC over both?