HTTP Methods (GET, POST, PUT, PATCH, DELETE)

HTTP methods tell the server what kind of action the client wants. REST maps these to resource operations: read, create, full replace, partial update, delete.

Method semantics at a glance

flowchart TB subgraph Safe["Safe (read-only)"] GET[GET - Read] end subgraph Idempotent["Idempotent (same result if repeated)"] PUT[PUT - Replace] DELETE[DELETE - Remove] end subgraph NonIdempotent["Non-idempotent (can create new)"] POST[POST - Create / action] PATCH[PATCH - Partial update] end
MethodTypical useBodyIdempotent?Safe?
GETRead resource(s)NoYesYes
POSTCreate or custom actionYesNoNo
PUTReplace resource (full)YesYesNo
PATCHPartial updateYesOftenNo
DELETERemove resourceOptionalYesNo

PUT vs PATCH

PUT replaces the whole resource: same URL, same body → same result (idempotent). PATCH sends only changed fields; repeating the same PATCH can be idempotent if the operation is defined that way (e.g. “set status to X”).

sequenceDiagram participant C as Client participant S as Server Note over C,S: PUT /users/1 - full replace C->>S: { "name":"Alice", "email":"a@b.com" } S->>S: Replace entire user S-->>C: 200 OK Note over C,S: PATCH /users/1 - partial update C->>S: { "email":"new@b.com" } S->>S: Update only email S-->>C: 200 OK