/ rest

PUT vs PATCH

ref: https://stackoverflow.com/questions/28459418/rest-api-put-vs-patch-with-real-life-examples

In my own words,

PUT

  • Used when inserting or replacing a record.

Example :

{
  "id": 1,
  "name": "Foo",
  "email": "bar@gmail.com"
}

PATCH

  • Used when updating a full, or partial section of a record.

Example:

{
  "email": "bar2@gmail.com"
}

When in doubt, look to a matured framework for explanation Edge Rails: PATCH is the new primary HTTP method for updates

There’s nothing theoretical preventing PUT from doing partial updates, but when HTTP was being standarized the replacement semantics were already deployed.

In practice, it doesn't matter depending on how the code handles the requests, but for semantics purposes, it is better to keep this difference in mind, and handle the operation in accordance to standards.

Idempotent operation

An idempotent operation is an operation that has no additional effect when called more than once.

PUT vs PATCH
Share this