What is the difference between PUT and PATCH in a REST API?
Learn the difference between PUT and PATCH in REST APIs: full replacement vs partial update, idempotency, examples, and when to use each with interview answers.
Expected Interview Answer
PUT replaces an entire resource with the full representation you send, while PATCH applies a partial update, changing only the fields you include and leaving the rest untouched.
With PUT you must send the complete resource; any field you omit is typically treated as cleared or reset, because the server swaps the whole record for your payload. PATCH sends only the delta, so it is smaller over the wire and ideal for updating one or two attributes. PUT is idempotent by definition — repeating the same full replacement leaves the same state — whereas PATCH is idempotent only if the patch itself is written to be (e.g., set field=value rather than increment).
- PUT gives predictable full-replacement semantics
- PATCH minimizes payload size for small edits
- PATCH avoids overwriting fields you did not intend to change
- PUT is reliably idempotent for safe retries
- Choosing correctly keeps the API intuitive for clients
AI Mentor Explanation
Updating a player's profile with PUT is like handing the scorer a brand-new team sheet that must list every player, or the missing names get dropped from the lineup entirely. PATCH is like sending a quick note saying only 'change the number 4 batter to number 3' — the rest of the batting order stays exactly as it was on the original sheet.
Step-by-Step Explanation
Step 1
Identify the intent
Decide whether the client is replacing the whole resource (PUT) or changing a subset of fields (PATCH).
Step 2
Build the payload
For PUT include the complete resource representation; for PATCH include only the fields to change.
Step 3
Handle omitted fields
On PUT, treat missing fields as cleared/reset; on PATCH, leave unspecified fields untouched.
Step 4
Preserve idempotency
Ensure PUT is a pure replacement; write PATCH bodies as absolute sets, not relative increments, to stay idempotent.
Step 5
Return the right status
Respond 200 with the updated body, or 204 when no content is returned; use 404 if the resource does not exist.
What Interviewer Expects
- Clear full-replacement vs partial-update distinction
- Awareness that PUT is idempotent by definition
- Understanding that PATCH idempotency depends on the patch body
- Correct handling of omitted fields under each method
- A concrete example of when to choose each
Common Mistakes
- Saying PATCH always replaces the whole resource
- Claiming PATCH is never idempotent
- Forgetting that omitted PUT fields can be cleared
- Using PUT for tiny single-field edits and sending huge payloads
- Confusing PATCH with POST for updates
Best Answer (HR Friendly)
“PUT swaps out an entire record with the complete new version you send, while PATCH just tweaks the specific parts you mention and leaves everything else alone. So PUT is a full replacement and PATCH is a partial edit.”
Code Example
PUT /users/42
Content-Type: application/json
{
"name": "Ada Lovelace",
"email": "[email protected]",
"role": "admin"
}PATCH /users/42
Content-Type: application/json
{
"email": "[email protected]"
}Follow-up Questions
- Why is PUT considered idempotent but POST is not?
- When would a PATCH request fail to be idempotent?
- What is JSON Patch and how does it differ from JSON Merge Patch?
- What status codes should PUT and PATCH return?
- How do you handle partial updates without a PATCH endpoint?
MCQ Practice
1. Which method is intended to replace an entire resource?
PUT sends the full representation and replaces the whole resource, unlike PATCH which updates only selected fields.
2. PATCH is idempotent when the request body...
Setting fields to absolute values yields the same state on repeat, while increments or toggles change state each time.
3. With PUT, a field omitted from the payload is typically...
Because PUT replaces the whole resource, omitted fields are commonly treated as cleared rather than preserved.
Flash Cards
What does PUT do? — Replaces the entire resource with the full representation in the request body.
What does PATCH do? — Applies a partial update, changing only the fields included in the body.
Is PUT idempotent? — Yes — repeating the same full replacement always yields the same resource state.
Is PATCH always idempotent? — No — only if the patch uses absolute sets, not relative operations like increments.