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.
Previous
What is compression middleware in Express and when should you use it?
Next
What is Passport.js and how does it integrate with Express?
More Express.js Questions
View all →- Intermediate How do you implement JWT authentication in Express.js?
- Intermediate What is Express middleware chaining and how does it work?
- Intermediate What is the helmet package and why should you use it?
- Intermediate How do you implement rate limiting in Express.js?
- Intermediate What is input validation and how do you do it in Express?