HTTP methods
HTTP methods describe what a request wants to do with a resource. Two properties matter most when you design an API: whether a method is safe (it only reads) and whether it is idempotent (repeating it has the same effect as doing it once).
HTTP methods
MDN reference
| Method | Purpose | Safe | Idempotent | Body |
|---|---|---|---|---|
GET | Retrieve a resource. | ✓ | ✓ | – |
HEAD | Like GET, but only the headers. | ✓ | ✓ | – |
POST | Submit data; creates something or triggers processing. | – | – | ✓ |
PUT | Replace a resource completely, or create it at a known URL. | – | ✓ | ✓ |
PATCH | Apply a partial change to a resource. | – | – | ✓ |
DELETE | Remove a resource. | – | ✓ | – |
OPTIONS | Ask which methods and headers a URL supports. Used by CORS preflight. | ✓ | ✓ | – |
CONNECT | Open a tunnel through a proxy, such as for HTTPS. | – | – | – |
TRACE | Echo the request back for diagnostics. Usually disabled for security. | ✓ | ✓ | – |
How to use it
- Use GET to read and never to change data.
- Use POST to create or trigger something.
- Use PUT to replace, PATCH to change part of a resource, and DELETE to remove it.
This tool is also built into Zest search, so you can type your question into the search box and get the same answer above the results.
Common questions
- What does idempotent mean?
- An idempotent method gives the same result however many times you repeat it. PUT and DELETE are idempotent, POST is not, so a retried POST can create a duplicate.
- PUT or PATCH?
- PUT replaces the whole resource with what you send. PATCH applies a partial change. If you only send some fields, use PATCH.