HTTP Methods Cheatsheet - REST/HTTP Verbs & Idempotency

When designing REST APIs you often wonder PUT vs PATCH, or which is idempotent. Grouped by method semantics, idempotency, safe attributes and status-code pairing, with copy-ready examples.

Reference·27 commands·Last updated 2026-08-02
Back to Reference

核心方法 Core Methods 7

GET
获取资源,安全且幂等,不应有副作用
POST
创建子资源或提交处理,非幂等
PUT
完整替换资源,幂等(重复请求结果一致)
PATCH
部分更新资源,通常不幂等(除非语义保证)
DELETE
删除资源,幂等(多次删结果一致)
HEAD
同 GET 但只返回头,用于探活/缓存校验
OPTIONS
查询目标支持的通信选项,CORS 预检用

幂等与安全性 Idempotency & Safety 4

安全方法
GET、HEAD、OPTIONS(不改变服务器状态)
幂等方法
GET、PUT、DELETE、HEAD、OPTIONS
非幂等
POST、PATCH(默认不保证重复请求一致)
Idempotency-Key
POST 重试时用请求头键避免重复创建

状态码搭配 Status Pairing 6

GET → 200 / 304
成功或命中缓存
POST → 201 / 202
创建成功或已接收异步处理
PUT → 200 / 204
替换成功,可返回新资源或空
PATCH → 200 / 204
部分更新成功
DELETE → 204 / 200
删除成功,无内容或返回摘要
方法不允许 → 405
对只支持 GET 的接口发 POST

常见误用 Mistakes 4

用 GET 改状态
违反安全语义,爬虫/预取会误触发副作用
PUT 当 PATCH 用
PUT 需传完整资源,缺字段会被清空
POST 重复提交
无幂等键时重试会创建重复资源
DELETE 返回 200 带正文
更规范是 204 No Content

REST 设计约定 6

GET /users
列表资源(集合)
GET /users/1
单个资源(子资源)
POST /users
新建资源
PUT /users/1
整体替换用户 1
PATCH /users/1
局部更新用户 1
DELETE /users/1
删除用户 1

💡 Tips

  • PUT sends the full resource — missing fields get cleared; use PATCH for partial updates.
  • GET/HEAD/OPTIONS are safe methods — never change server state inside them.
  • Retrying POST needs an Idempotency-Key, or you may create duplicate resources.
  • The HTTP Status Codes sheet is provided separately; use both when designing APIs.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Aug 2, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it