ゆるテックノート

HTTP method anti-patterns

A guide to method properties and potential implementation problems. Choosing POST is not, by itself, a specification violation.

Frequent pitfalls

What goes wrong and how to fix it.

Patterns to avoid

Pattern Why it’s bad Fix
State changes on GET Prefetchers and link previews will trigger it; violates safety. Move requested mutations to POST/PUT/PATCH/DELETE. Incidental access logging is a different matter.
Unclear POST retry contract POST supports many operations but does not automatically guarantee idempotency. Use methods such as PUT where their semantics fit; document POST duplicate prevention and state checks.
Repeated DELETE removes another target Deleting the next item on each identical request has a different effect from one request. Identify a fixed target. A first 204 and a later 404 do not, by themselves, violate idempotency.
PUT/PATCH without conditions Concurrent edits overwrite each other. Where conflict detection is needed, use strong ETags and If-Match: 412 for a failed condition and, for example, 428 when a required condition is missing.
Bodies on GET Semantics undefined; intermediaries may drop them. Usually use query parameters. Design a processing POST for body-based searches; do not misuse PUT/PATCH for retrieval.
POST with sloppy status codes Only 200/500 makes clients guess; duplicates become errors. Use 201/204/409/412 appropriately and include Location/error details.
Blocking OPTIONS CORS preflight fails and actual requests never arrive. Allow only origins, methods, and headers consistent with the API policy. CORS does not replace authentication or CSRF protection.

Warning signs

If you see these symptoms, revisit method usage.

Checklist

  • Only 200 and 500 are used in the API.
  • Crawling GET endpoints triggers requested mutations such as purchases or deletions.
  • Duplicate submissions create unintended duplicates.
  • For CORS failures, inspect whether OPTIONS was sent and what it returned. Sometimes the actual request has already run and only reading the response is denied.
  • Specs lack statements on safety/idempotency per method.

Takeaway

For retries, check whether unintended extra actions occur rather than whether status codes stay identical. Continue with method properties, conflict prevention, and CORS behavior.

Specifications

RFC 9110 §9 / RFC 9110 §13 / RFC 6585 §3 / Fetch: CORS protocol