TechnicalEasy HTTP & REST APIs
Explain the HTTP methods GET, POST, PUT, PATCH and DELETE. Which ones are idempotent?
Asked for Frontend Developer, Backend Developer, Full-Stack Developer, Mobile Developer
Why they ask this: Every developer calls or builds APIs; correct method use is a basic expectation.
Answer
| Method | Use | Safe | Idempotent |
|---|---|---|---|
GET | read a resource | yes | yes |
POST | create a resource or trigger an action | no | no |
PUT | replace a resource completely | no | yes |
PATCH | update part of a resource | no | not guaranteed |
DELETE | remove a resource | no | yes |
- Safe means the request does not change server data.
- Idempotent means sending the same request several times leaves the server in the same state as sending it once. Two identical
POST /orderscalls can create two orders, whilePUT /users/5with the same body twice gives the same result.
This matters for retries: clients and proxies can safely retry idempotent requests after a network error. For payments, use an idempotency key to make POST safe to retry.
Can you explain this in your own words?