Sobes.tech
Middle

What is the difference between PUT and PATCH in REST API?

sobes.tech AI

Answer from AI

In REST API, the PUT and PATCH methods are used for updating resources but differ in meaning and behavior:

  • PUT — full update of a resource. When calling PUT, the client sends a complete representation of the resource, and the server replaces the existing resource with the one sent. If some fields are not specified, they are usually cleared or removed.

  • PATCH — partial update of a resource. The client sends only the fields that need to be changed, and the server updates only those, leaving the rest unchanged.

Example:

PUT /users/123
{
  "name": "Ivan",
  "email": "ivan@example.com"
}

Replaces the entire user profile.

PATCH /users/123
{
  "email": "new_email@example.com"
}

Updates only the email, other data remains the same.

What is the difference between PUT and PATCH in REST… - sobes.tech