Category: java
PUT vs PATCH HTTP Methods
Published on 24 Feb 2026
Explanation
PUT method is used to completely
update a resource.
Code:
fetch('/users/1', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Updated Name' })
});
Explanation
PATCH method is used to partially update a
resource.
Code:
fetch('/users/1', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: 'new@mail.com' })
});
Explanation
PUT replaces entire resource,
missing fields may be removed.
Code:
// PUT replaces full object
Explanation
PATCH modifies only specified fields.
Code:
// PATCH updates only provided fields
Explanation
Both PUT and PATCH are idempotent
if used correctly.
Code:
// Multiple identical PUT calls result in same resource state