🚀 Express.js Intermediate

What is the difference between PUT and PATCH in REST?

Answer

PUT is a full replacement operation — it replaces the entire resource with the data sent in the request body. If the client omits a field, the server treats it as null/removed. PUT is idempotent: calling it multiple times with the same data produces the same result. PATCH is a partial update — it applies changes only to the fields included in the request body, leaving other fields unchanged. PATCH is also idempotent in practice but not required to be by spec. In Express: router.put('/:id', replaceUser); router.patch('/:id', updateUserFields);. Most REST APIs use PATCH for update operations because clients rarely need to send the complete resource just to change one field.