The HTTP methods as an API contract: meaning of each, the safe, idempotent and cacheable properties, body rules, and how retries, caches and proxies rely on them.
GET reads, POST creates or runs a command, PUT replaces a resource at a known URI, PATCH partially updates it, DELETE removes it, HEAD is GET without the body, and OPTIONS asks what is allowed (used by CORS preflight).
These properties are a contract that caches, proxies, browsers and retry policies rely on: a gateway may retry a timed-out PUT but must not blindly retry a POST. Breaking the contract, such as changing state on GET, causes duplicate side effects and crawler disasters.
"I think of the methods as a contract between my API and everything in between: browsers, CDNs, gateways and retry policies. GET reads a representation. POST submits something for the server to process, usually creating a resource in a collection or running a command. PUT replaces the resource at the URI I name, and can create it if the client owns the id. PATCH applies a partial change. DELETE removes the resource. HEAD is GET without the body, handy for existence or size checks. OPTIONS asks which methods and headers are allowed, and browsers send it as the CORS preflight.
Two properties matter. A safe method has no intended side effects: GET, HEAD and OPTIONS. An idempotent method has the same effect on the server whether you send it once or five times: the safe methods plus PUT and DELETE. POST and PATCH are neither by definition. Idempotency is about state, not the response: the first DELETE returns 204 and the second may return 404, but the order is gone either way. In ASP.NET Core I express this with
MapGet,MapPut,MapDeleteand so on, and resilience handlers onHttpClientcan then decide what's safe to retry.The mistake I see is treating methods as interchangeable labels: a GET that sends an email, or POST used for everything. That breaks caches, makes link prefetchers trigger actions and means a timeout can't be retried safely. If an operation must be retryable but isn't naturally idempotent, like taking a payment, I make it idempotent with an idempotency key rather than pretending POST is safe."
| Method | Meaning | Safe | Idempotent | Request body | Cacheable |
|---|---|---|---|---|---|
| GET | Read representation | Yes | Yes | No defined semantics | Yes |
| HEAD | GET without body | Yes | Yes | No defined semantics | Yes |
| OPTIONS | Allowed methods / CORS preflight | Yes | Yes | Rarely | No |
| POST | Process / create in collection | No | No | Yes | Only with explicit freshness info |
| PUT | Replace at this URI | No | Yes | Yes | No |
| PATCH | Partial update | No | No (can be designed to be) | Yes | No |
| DELETE | Remove | No | Yes | No defined semantics | No |
| Operation | Method and URI | Success |
|---|---|---|
| List orders | GET /orders |
200 |
| Get one | GET /orders/42 |
200 / 404 |
| Create (server id) | POST /orders |
201 + Location |
| Create or replace (client id) | PUT /orders/{guid} |
201 or 200/204 |
| Partial update | PATCH /orders/42 |
200 / 204 |
| Delete | DELETE /orders/42 |
204 |
A [reporting] API exposed GET /reports/{id}/regenerate. A browser extension that prefetched links triggered [hundreds of] regenerations a day, each costing ~40 s of SQL CPU. Changing it to POST /reports/{id}/regenerations (202 Accepted) stopped the accidental load overnight.
Checks that the candidate knows method semantics precisely and understands why caches, proxies and retry policies depend on them.
Green flags
Red flags
RFC 9110 (HTTP Semantics, 2022) defines GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE. PATCH is defined separately in RFC 5789. The safe and idempotent properties are promises the server makes; intermediaries are allowed to act on them.
A GET may write an access log or increment a view counter. Safe means the client did not request a state change and is not responsible for it. If GET triggers business effects (sending email, deleting data), crawlers, prefetchers, link previews in chat apps and security scanners will trigger them too.
PUT /orders/42 {status: Shipped} x3 -> state: Shipped (same as once)
DELETE /orders/42 x3 -> state: gone (204, then 404, 404)
POST /orders {...} x3 -> state: three orders (not idempotent)
PATCH /orders/42 [{op: add, path: /lines/-, ...}] x3 -> three lines added
PATCH with JSON Merge Patch that sets fields to fixed values happens to be idempotent; PATCH with a JSON Patch add to an array is not. That is why the RFC does not promise it.
Client --> API gateway --> Service
| timeout after 30 s
| Is it safe to retry?
| GET/PUT/DELETE: yes, the effect is the same
| POST/PATCH: unknown, it may have run already
The .NET resilience pipeline (Microsoft.Extensions.Http.Resilience, AddStandardResilienceHandler) retries transient failures, and you can disable retries for unsafe methods (DisableForUnsafeHttpMethods()). Browsers automatically retry idempotent requests on some connection failures; HTTP/2 GOAWAY handling also relies on it.
GET and HEAD responses are cacheable by default when freshness information is present (Cache-Control: max-age, Expires) or heuristically. POST responses are cacheable only with explicit freshness and a Content-Location, which almost nobody uses. A successful PUT, PATCH, POST or DELETE must invalidate cached entries for the target URI.
MapGet, MapPost, MapPut, MapPatch, MapDelete and MapMethods add HttpMethodMetadata. If a path matches but the method doesn't, routing returns 405 Method Not Allowed with an Allow header. HEAD is not routed to GET automatically for Minimal APIs; you map it with MapMethods(path, ["GET", "HEAD"], ...) or let a framework layer handle it.
MapGet only, then call it with curl -X DELETE -i and inspect the 405 and Allow header.WebApplicationFactory that sends the same PUT three times and asserts the stored state is identical.AddStandardResilienceHandler with options.Retry.DisableForUnsafeHttpMethods() and log which calls get retried.Endpoints that respect method semantics, plus a client-side resilience handler that retries only idempotent methods.
// Program.cs (.NET 10)
using System.Collections.Concurrent;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var orders = new ConcurrentDictionary<Guid, Order>();
app.MapGet("/orders/{id:guid}", (Guid id) =>
orders.TryGetValue(id, out var o) ? Results.Ok(o) : Results.NotFound());
// POST: server assigns the id; not idempotent.
app.MapPost("/orders", (CreateOrder cmd) =>
{
var order = new Order(Guid.NewGuid(), cmd.CustomerId, "Pending");
orders[order.Id] = order;
return Results.Created($"/orders/{order.Id}", order);
});
// PUT: client names the id; repeating it gives the same state.
app.MapPut("/orders/{id:guid}", (Guid id, ReplaceOrder body) =>
{
var created = !orders.ContainsKey(id);
var order = new Order(id, body.CustomerId, body.Status);
orders[id] = order;
return created ? Results.Created($"/orders/{id}", order) : Results.Ok(order);
});
// DELETE: idempotent in effect; the response may differ on repeat.
app.MapDelete("/orders/{id:guid}", (Guid id) =>
orders.TryRemove(id, out _) ? Results.NoContent() : Results.NotFound());
app.Run();
public sealed record Order(Guid Id, int CustomerId, string Status);
public sealed record CreateOrder(int CustomerId);
public sealed record ReplaceOrder(int CustomerId, string Status);
// Client side: retry transient failures, but never blindly for POST/PATCH.
// Package: Microsoft.Extensions.Http.Resilience
builder.Services.AddHttpClient("orders", c => c.BaseAddress = new Uri("https://orders.internal"))
.AddStandardResilienceHandler(options =>
{
options.Retry.DisableForUnsafeHttpMethods(); // POST, PATCH, CONNECT are not retried
});
GET /orders/42/cancel). Why it is wrong: Crawlers, prefetchers, link previews and caches assume GET is safe and will trigger it. Instead: Use POST (or PATCH/DELETE) for anything with side effects.POST /orders/search.The senior point is that method semantics are not style: they are what lets infrastructure you don't control behave correctly. A CDN caches GETs, a gateway retries PUTs, a browser preflights non-simple requests. When you get the method right you get those behaviours for free; when you get it wrong you get duplicate side effects in production.
In microservices this compounds. A service-to-service call usually passes through a client resilience handler, a service mesh sidecar and maybe a gateway, and each layer may retry. If a POST that charges a card is retried at three layers with three attempts each, one user click can become up to 27 charges. So either the method is idempotent, or the operation carries an idempotency key that every layer forwards, and retries are configured at one layer only.
| Operation shape | Method | Why | Watch out |
|---|---|---|---|
| Read, no side effects | GET | Cacheable, safe to retry | Keep URLs free of personal data |
| Create, server assigns id | POST | Not idempotent, so add an idempotency key if retries matter | Return 201 + Location |
| Create/replace, client owns id | PUT | Idempotent, retry-safe | Must send the full representation |
| Partial update | PATCH | Small payloads | Not idempotent by default; use If-Match for concurrency |
| Remove | DELETE | Idempotent | Decide whether the repeat returns 204 or 404 and document it |
HTTP is a request/response protocol: method + path + headers (+ body) in, status + headers (+ body) out.
GET/HEAD/OPTIONS are safe; GET, PUT, DELETE are idempotent (repeating has the same effect); POST and usually PATCH are not, so retries need an idempotency key.Content-Type, Accept, Authorization, Cache-Control, ETag/If-None-Match, Retry-After, traceparent.Have the client send a unique Idempotency-Key header per logical operation (one checkout attempt, not one HTTP attempt), and scope keys per client or API key so one caller can't replay another's. The server stores the key with a hash of the request and the response, atomically with the side effect (same transaction, or a unique constraint on the key). A repeat with the same key and body returns the stored response; the same key with a different body returns 422; a concurrent duplicate gets 409 until the first completes. Keys expire after a documented window such as 24 hours, enforced with a TTL (Redis) or a cleanup job (SQL). Log key reuse and mismatches so replay attempts and buggy clients show up in monitoring.
Last updated 23 Nov 2026.