Middle
How does PUT differ from PATCH?
sobes.tech AI
Answer from AI
PUT and PATCH are HTTP methods for updating resources, but they differ in meaning and behavior:
- PUT replaces the entire resource. When you send a PUT request, the server expects a complete representation of the resource, and the existing resource will be fully overwritten.
- PATCH is used for partial updates. Only the fields that need to be changed are sent in the request body, and the rest remain unchanged.
For example, if you have a user object with fields name, email, and phone:
- A PUT request must contain all three fields; otherwise, missing fields will be deleted.
- A PATCH request can contain only the email to update just that, without touching the other fields.