PATCH: Partial Updates
You'll learn when and how to use HTTP PATCH to modify only specific parts of a resource without replacing the whole thing.
What PATCH Does
While PUT replaces an entire resource (like rewriting a whole document), PATCH modifies only the fields you specify. Think of it like using correction tape on a paper form—you only change the parts that need fixing, leaving everything else untouched.
When you PATCH a resource, you send only the fields you want to update. The server applies those changes without affecting other properties.
PATCH vs PUT: When to Use Each
Use PATCH when:
- You want to update just one or two fields (like changing a user's email)
- The resource is large and you don't want to send the entire object
- Different clients might update different fields independently
Use PUT when:
- You're replacing the entire resource
- You want clear "last write wins" semantics
- You're sending a complete representation
Example Scenario
Imagine updating a user profile. With PUT, you'd send the complete user object—name, email, avatar, bio, settings, everything. With PATCH, you send only what changed:
PATCH /api/users/123
Content-Type: application/json
{
"email": "newemail@example.com"
}
The server updates only the email field. Everything else (name, avatar, bio) stays the same.
Key Considerations
PATCH is NOT guaranteed to be idempotent (though it often is). Sending the same PATCH twice usually produces the same result, but the HTTP spec doesn't require it. PATCH operations can be more complex because the server must merge changes with existing data.
Key Takeaway: Use PATCH for partial updates when you only need to change specific fields, and PUT when you're replacing the entire resource representation.