Middle
What is the difference between PUT and PATCH?
sobes.tech AI
Answer from AI
PUT and PATCH are HTTP methods for updating resources, but they differ in meaning and application:
-
PUT replaces the entire resource. If a field is not specified in the request body, it will be deleted or reset to its default value. PUT is idempotent — repeated requests with the same data will not change the result.
-
PATCH is used for partial updates of a resource. Only the fields that need to be changed are specified in the request body; others remain unchanged. PATCH is not necessarily idempotent, depending on the implementation.
Example: if a user has fields name, email, age, then
- PUT with body {"name": "Ivan", "email": "ivan@example.com"} will replace the entire resource, possibly resetting age
- PATCH with the same body will update only name and email, leaving age unchanged.