HTTP Methods: GET, POST, PUT, PATCH and DELETE
Know what each HTTP method promises, which ones are safe to repeat and how to choose the right one for a form or API.
Key takeaways
-
GETandHEADare meant for reading, so they should never change anything the user cares about. -
PUTandDELETEare idempotent: sending the same request again leaves the server in the same state. -
POSTis the general-purpose method for processing data and is not safe to repeat blindly. -
PATCHsends a set of changes, and its format determines what repeating it does. - A method is a convention the server must honor in code; nothing in the network enforces it.
The method is the first word of an HTTP request, and it states your intent. GET asks to read something, POST hands data to the server to process, PUT replaces a resource, PATCH changes part of it and DELETE removes it.
The differences matter because browsers, caches, proxies and client libraries treat methods differently. Pick the wrong one and you can end up with a cached response that should have been fresh, an order placed twice, or records deleted by a crawler that was only following links.
Two properties that explain everything
The HTTP semantics standard, RFC 9110, describes methods with two properties worth learning first.
A method is safe if its purpose is read-only. The client is not asking for any change. A server may still write a log line or count a visit, but the user has not requested an action and is not responsible for side effects.
A method is idempotent if making the same request several times has the same intended effect on the server as making it once. Turning a light "on" is idempotent. Pressing a toggle switch is not.
| Method | Safe | Idempotent | Typical use |
|---|---|---|---|
| GET | Yes | Yes | Read a page or record |
| HEAD | Yes | Yes | Read only the headers |
| OPTIONS | Yes | Yes | Ask what is allowed |
| POST | No | No | Submit data, create, trigger an action |
| PUT | No | Yes | Create or replace at a known address |
| PATCH | No | Not guaranteed | Apply partial changes |
| DELETE | No | Yes | Remove a resource |
Idempotence is what lets a client retry after a dropped connection. If a PUT times out, sending it again is reasonable. If a POST times out, you do not know whether the server acted, and a second attempt might do the thing twice.
GET: reading
GET retrieves a representation of a resource. Typing an address, clicking a link and loading an image are all GET requests.
Parameters go in the URL's query string, such as /search?q=routers&page=2. That makes the result bookmarkable and shareable. It also means the values can appear in browser history and server logs, so passwords and other secrets do not belong there.
A GET request can technically carry a body, but the standard gives it no defined meaning, and many servers and proxies ignore or reject it. If a query is too large or too sensitive for the URL, APIs commonly accept a POST to a search address instead.
Responses to GET are the main thing caches store. HEAD is its quiet sibling: the same headers the server would send for a GET, with no body. It is useful for checking whether a file exists or how large it is.
POST: processing and creating
POST asks the target resource to process the enclosed data according to its own rules. That covers submitting a form, adding a comment, uploading a file, starting a job or logging in.
When a POST creates something new, a well-behaved API answers 201 Created and puts the new item's address in a Location header:
POST /articles HTTP/1.1
Host: api.example.com
Content-Type: application/json
{"title": "Router basics"} HTTP/1.1 201 Created
Location: /articles/42 The server chose the identifier, which is the usual reason to create with POST.
Websites also face the double-submit problem: a visitor refreshes after submitting and the browser offers to send the form again. The standard remedy is Post/Redirect/Get. The server handles the POST, then answers with 303 See Other pointing at a confirmation page, and refreshing that page only repeats a harmless GET.
PUT: replacing
PUT means "make the resource at this address look like what I am sending". The client names the address and supplies the complete new representation.
PUT /users/17/preferences HTTP/1.1
Content-Type: application/json
{"theme": "dark", "emails": false} If you omit a field in a PUT, you are saying the new version does not have it. A server that merges missing fields with old ones is behaving like PATCH, and that surprises clients. If the address did not exist and the server creates it, the answer is 201. If it existed, 200 or 204 No Content is usual.
PATCH: changing part
PATCH, defined in RFC 5789, sends instructions for modifying a resource. The body is a description of changes, so the format matters, and Content-Type should say which one you used.
Two standard JSON formats are common:
- JSON Merge Patch (
application/merge-patch+json, RFC 7396) looks like a fragment of the object. Supplied fields are replaced, and a field set tonullis removed. - JSON Patch (
application/json-patch+json, RFC 6902) is a list of operations such as add, remove and replace, each with a path.
A patch that says "set the theme to dark" happens to be idempotent. A patch that says "append this item to the list" is not. That is why the method as a whole makes no promise.
DELETE: removing
DELETE asks the server to remove the association between the address and the resource. Common success answers are 204 No Content, 200 with a short report, or 202 Accepted when the work will happen later.
Idempotence here refers to the effect, not the response. The first DELETE might return 204 and the second 404, yet the state is the same: the item is gone. Many services do not erase data immediately and only mark it deleted, which is a policy decision invisible to the method.
Choosing a method
HTML forms only support GET and POST natively. To use the others from a web page you send the request with JavaScript, or the server framework accepts a hidden field that stands in for the method.
Making POST safe to retry
Payments and orders are the cases where repeating a request hurts. A widely used solution is an idempotency key: the client generates a unique value for the operation and sends it in a header, often named Idempotency-Key. The server records it with the result. If the same key arrives again, it returns the stored result and does no new work.
The header is a convention that each API defines for itself, so read its documentation for how long keys are remembered. Pair retries with increasing delays; the retry and backoff simulator shows how those schedules spread out, and polite API clients explains why that matters.
Answering each method well
The method and the status code form a pair. A client that sees the right combination knows what happened without parsing any prose.
| Request | Success | Common failures |
|---|---|---|
| GET an item | 200, or 304 if unchanged | 404 missing |
| POST to create | 201 with Location | 400 or 422 bad data, 409 conflict |
| PUT an item | 200, 201 or 204 | 409 conflict, 412 stale version |
| PATCH an item | 200 or 204 | 415 unknown patch format, 422 cannot apply |
| DELETE an item | 200, 202 or 204 | 403 not allowed, 404 already gone |
A 204 response has no body, so use 200 if you want to return the updated object. A 202 only says the request was accepted for later processing, so give the client a way to check on it, such as a status address it can read with GET.
For error details, APIs can follow the "problem details" format in RFC 9457, a small JSON object with fields such as a title and a detail message. Whatever shape you pick, use it for every method so clients need only one error handler.
OPTIONS and other methods
OPTIONS asks what a server supports for a resource. You will mostly meet it as the preflight request a browser sends before certain cross-origin calls, explained in CORS explained. CONNECT asks a proxy to open a tunnel, which is how HTTPS passes through many corporate proxies. TRACE echoes a request for diagnostics and is commonly disabled.
If a server recognizes a method but the resource does not allow it, the correct answer is 405 Method Not Allowed with an Allow header listing the ones that work. 501 Not Implemented means the server does not support the method at all.
Mistakes that cause real trouble
Changing data on GET. A link such as /items/5/delete looks convenient until a crawler, a link scanner in an email filter or a browser prefetch follows it.
Assuming POST is secure. The body does not appear in the address bar, but without HTTPS it travels in readable form just like a URL.
Trusting the method for access control. Every method that changes data needs its own permission check on the server. Blocking DELETE in the interface does nothing against a hand-made request.
Forgetting cross-site request forgery. Browsers attach cookies automatically in many situations, so state-changing requests need defenses such as anti-forgery tokens and SameSite cookie settings.
Ignoring conditional updates. Two people editing the same record can overwrite each other with PUT. Sending If-Match with the version's ETag lets the server refuse a stale write with 412 Precondition Failed. See ETags and conditional requests.
Trying methods from the command line
On macOS, Linux or Windows (use curl.exe in Windows PowerShell 5.1):
curl -I https://www.example.com/
curl -X OPTIONS -i https://www.example.com/
curl -X DELETE -i https://api.example.com/articles/42 Run anything that modifies data only against systems you own or have permission to change. For how these methods are arranged into a coherent interface, read REST APIs explained.