HTTP Methods: GET, POST, PUT, PATCH and DELETE Explained

Short answer: GET reads a resource, POST creates one or triggers an action, PUT replaces a resource with the data you send, PATCH changes part of it, and DELETE removes it. HEAD is a GET without the response body, and OPTIONS asks what the server allows.

The method tells the server what you intend to do with the URL. It also decides whether a request can be retried safely, whether it can be cached, and whether the browser sends a CORS preflight first. Here is how each one works, with fetch() examples tested against a small local API. They run in the browser and in Node.js 18 or newer, where fetch() is built in (here’s how to check your Node version).

HTTP methods at a glance

These properties come from the HTTP spec (RFC 9110, plus RFC 5789 for PATCH). Safe means the request is read-only. Idempotent means sending it once or ten times has the same intended effect on the server.

Method Use it to Safe Idempotent Cacheable Request body
GET Read a resource Yes Yes Yes No
HEAD Read only the headers Yes Yes Yes No
POST Create a resource, submit a form, run an action No No Rarely* Yes
PUT Replace a resource (or create it at a known URL) No Yes No Yes
PATCH Change part of a resource No No Rarely* Yes
DELETE Remove a resource No Yes No Avoid
OPTIONS Ask which methods and headers are allowed Yes Yes No Avoid

* Only when the response includes explicit freshness information and a matching Content-Location header. In practice, browsers and CDNs cache GET and HEAD responses, not POST or PATCH.

“Avoid” means the spec gives a body on that method no defined meaning, so some servers and proxies ignore or reject it. For GET and HEAD, fetch() refuses outright: it throws TypeError: Request with GET/HEAD method cannot have body. Put filters in the query string instead; URLSearchParams builds it for you. The spec also lists CONNECT (for proxy tunnels) and TRACE (a loop-back test), which you won’t use when building an API.

Safe and idempotent describe what the client asked for, not what the server actually does. A server can still log every GET. The point is that a GET link must never delete data, because crawlers, link previews and browser prefetching all follow links freely.

GET: read data

GET is what the browser sends when you open a URL. It should only fetch data. A successful response is usually 200 OK, or 404 Not Found if the resource doesn’t exist. Note that fetch() doesn’t throw on a 404 or 500; it only throws on network errors, so check response.ok.

const res = await fetch('/api/todos/1');

if (!res.ok) {
  throw new Error(`HTTP ${res.status}`);
}

const todo = await res.json();
// { id: 1, title: 'Buy milk', done: false }

POST: create something or run an action

POST sends data to a collection URL, and the server decides where the new resource lives. A good API answers 201 Created with a Location header pointing at the new resource. Because POST isn’t idempotent, sending it twice usually creates two records. That’s why browsers warn you before resubmitting a form.

const res = await fetch('/api/todos', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ title: 'Write post', done: false }),
});

res.status;                  // 201
res.headers.get('Location'); // '/api/todos/2'
await res.json();            // { id: 2, title: 'Write post', done: false }

PUT vs PATCH vs POST

This is where most confusion is, so here is the difference in one line each:

  • POST to /api/todos: “add this to the collection, you pick the ID.”
  • PUT to /api/todos/2: “make resource 2 exactly this.” Fields you leave out are gone.
  • PATCH to /api/todos/2: “change only these fields.” Everything else stays.

PUT is idempotent: sending the same full object twice leaves the same result. If the resource didn’t exist yet and the server lets you create it with PUT, it must answer 201 Created; when it updates an existing one, it answers 200 OK or 204 No Content.

PATCH is not idempotent by definition, because a patch can say “add 1 to the counter” or “append this item”. A patch that only sets fields to fixed values, like { "done": true }, happens to be safe to repeat.

PUT replaces, PATCH merges

Run one after the other against the same todo, the two requests below behave differently. The PUT sends no done field, so the stored todo loses it. This is the classic PUT bug: sending a partial object and wiping fields.

// Stored: { id: 2, title: 'Write post', done: false }

await fetch('/api/todos/2', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ title: 'Write post' }),
});
// Stored now: { id: 2, title: 'Write post' }   <- done is gone

await fetch('/api/todos/2', {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ done: true }),
});
// Stored now: { id: 2, title: 'Write post', done: true }

Write PATCH in uppercase

fetch() normalizes get, head, post, put, delete and options to uppercase, but not patch. Method names are case-sensitive, so method: 'patch' goes out as a lowercase patch, which most servers reject. Node.js even prints a warning about it. Always write methods in uppercase.

fetch(url, { method: 'patch' }); // sent as "patch" -> 400 or 405
fetch(url, { method: 'PATCH' }); // works

DELETE: remove a resource

DELETE is idempotent: after the first call the resource is gone, and calling again doesn’t remove anything else. The status code can differ, though. The first call usually returns 204 No Content (or 200 with a body), and a repeat returns 404. Idempotency is about the state on the server, not about getting the same response.

const res = await fetch('/api/todos/1', { method: 'DELETE' });
res.status; // 204 the first time, 404 the second time

HEAD and OPTIONS

HEAD returns the same headers as GET with no body. Use it to check that a URL exists, or read its Content-Length or Last-Modified without downloading it. OPTIONS asks the server what’s allowed; you’ll mostly see it sent by the browser itself, as a CORS preflight.

const res = await fetch('/api/todos/2', { method: 'HEAD' });
res.status;                      // 200
res.headers.get('Content-Type'); // 'application/json'
await res.text();                // '' (no body)

CORS preflight: why you see an OPTIONS request

When a page calls an API on a different origin, the browser may send an OPTIONS request first, called a preflight, to ask permission. It skips the preflight only for “simple” requests: GET, HEAD or POST, with no custom headers, and a Content-Type of application/x-www-form-urlencoded, multipart/form-data or text/plain. A PUT, PATCH or DELETE, or a POST with Content-Type: application/json, always gets a preflight.

The server has to answer the OPTIONS request with a 2xx status and the right Access-Control-Allow-Origin, Access-Control-Allow-Methods and Access-Control-Allow-Headers headers. If it doesn’t, the browser never sends the real request, and fetch() fails with a generic network error. Access-Control-Max-Age lets the browser cache the answer for a while, so it doesn’t preflight every call. The full rules are on MDN’s CORS guide.

A minimal preflight response

The headers your API must send for a cross-origin PATCH with a JSON body. Allow the exact origin of your front end; don’t reflect any origin back if the API uses cookies.

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 600

Which status codes go with which method

  • GET: 200, or 404 when the resource doesn’t exist.
  • POST: 201 with a Location header when it created something, 200 or 204 for actions.
  • PUT and PATCH: 200 with the updated resource, or 204; 201 when PUT created it.
  • DELETE: 204, or 200 with a body.
  • Any method the URL doesn’t support: 405 Method Not Allowed with an Allow header listing the ones it does.

Every code is explained in the HTTP status codes reference.

FAQ

What is the difference between GET and POST?

GET reads data, puts any parameters in the URL, and can be cached, bookmarked and retried. POST sends data in the request body to create something or trigger an action, isn’t cached, and can have side effects if repeated.

Is HTTPS a different set of methods?

No. HTTPS is HTTP over an encrypted (TLS) connection, so the methods and status codes are exactly the same.

Can a GET request have a body?

The spec gives it no meaning, and many servers and proxies ignore or reject it. fetch() throws if you try. Send parameters in the query string, or use POST for large search queries.

Should I use PUT or PATCH to update data?

Use PATCH when the client sends only the fields that changed, which is the common case in forms. Use PUT when the client always sends the complete resource.

How many HTTP methods are there?

RFC 9110 defines eight: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE. PATCH comes from RFC 5789. Web APIs use mostly GET, POST, PUT, PATCH and DELETE.