Sobes.tech
Middle

What is the difference between PUT and PATCH requests?

sobes.tech AI

Answer from AI

PUT and PATCH are HTTP methods for updating resources, but they differ in how they perform the update:

  • PUT replaces the entire resource. If some fields are missing in the request body, they will be deleted or reset to default values. PUT is idempotent, meaning repeated requests with the same data will not change the result.

  • PATCH updates only the specified fields of the resource, leaving others unchanged. This is a partial update. PATCH is not necessarily idempotent, depending on the implementation.

Example:

PUT /users/123
{
  "name": "Ivan",
  "age": 30
}

Will replace the entire user profile; if the "age" field is removed, it will be deleted.

PATCH /users/123
{
  "age": 31
}

Will only update the age, leaving other data unchanged.