A PATCH request applies a partial update to an existing resource, changing only the fields you send and leaving the rest untouched. The detail most people get wrong is that PATCH has no single fixed body format: the meaning of the request depends on the media type you declare, usually JSON Merge Patch or JSON Patch.
That flexibility is the whole point. PUT sends a full replacement, so a client must know every field and resend it. PATCH sends a small diff, which is safer when records are large or when several people edit them at once.
PATCH Sends Only the Fields You Name
The server reads your body, finds the target record by its URL, and applies the change. Any field you omit keeps its current value. That is the contract, and it is why PATCH is described as a partial update.
The body must describe the change in a format the server understands. If you send raw JSON with an ordinary content type such as application/json, the server needs its own documented rules for what a missing field means. Without those rules, behaviour varies between implementations and bugs follow.
Two standard formats remove that ambiguity:
- JSON Merge Patch (media type application/merge-patch+json) treats the body as a set of fields to merge. A key with a value sets that field. A key set to null removes it. Nested objects merge one level at a time.
- JSON Patch (media type application/json-patch+json) treats the body as a list of operations. Each operation has an op, a path, and for most operations a value. Operations include add, remove, replace, move, copy and test.
Merge Patch is shorter and easier to read. JSON Patch is precise and can express array edits and conditional changes. Pick one and state it in your API documentation, because clients cannot guess.
PATCH Versus PUT: Which One Changes What
The distinction is about scope, not about size. PUT is defined as replacing the resource at the target URL with the representation you send. PATCH is defined as applying a set of changes to that resource.
In practice, many APIs use PUT loosely for partial updates. That works until a client omits a field expecting it to stay, and the server clears it instead. If your API behaves that way, document it clearly and treat the field list as required.
| Behaviour | PUT | PATCH |
|---|---|---|
| Fields not sent | Usually reset or rejected | Left unchanged |
| Body size | Full representation | Only the changed part |
| Common media type | application/json | application/merge-patch+json or application/json-patch+json |
| Safe to repeat | Yes, same result each time | Usually, if the change sets fixed values |
| Best for | Whole-record saves and creation with a known URL | Single-field edits, status changes, large records |
Note the repeat question. Sending the same PATCH twice is normally fine when it sets a field to a fixed value. It is not fine when the body says "increment the count" or "append to the list", because a retry applies the change twice. Design operations to be repeatable where you can.
A PATCH Request You Can Trace Line by Line
Suppose a customer record lives at /customers/42 and currently reads:
{
"id": 42,
"name": "Sam Okafor",
"email": "sam@example.com",
"plan": "basic",
"active": true
}
You want to move the customer to the pro plan and clear a stale note field. With Merge Patch you send:
PATCH /customers/42
Content-Type: application/merge-patch+json
{ "plan": "pro", "note": null }
The server checks the record exists, applies plan as pro, sets note to null so it disappears, and leaves name, email and active alone. A successful response often returns 200 with the updated record, or 204 with an empty body. Both are acceptable; check your API's convention.
The same change in JSON Patch needs an array of operations:
[
{ "op": "replace", "path": "/plan", "value": "pro" },
{ "op": "remove", "path": "/note" }
]
JSON Patch fails the whole request if any path is missing, unless you use add instead of replace. That strictness is useful when a missing field should signal a problem rather than pass silently.
Status Codes and Headers That Tell You What Happened
A successful PATCH usually returns 200 when the body carries the updated resource, or 204 when it does not. Some APIs return 202 when the change is queued for processing, and the response should then explain how to check progress.
Failures matter more than successes, because they tell you what to fix:
- 400 Bad Request: the body is malformed, or a path in a JSON Patch does not exist.
- 404 Not Found: the record itself does not exist at that URL.
- 409 Conflict: the change clashes with the current state, for example editing a record someone else has already changed.
- 415 Unsupported Media Type: the server does not accept the format you declared.
- 422 Unprocessable Entity: the format is valid but a value breaks a rule, such as an unknown plan name.
Use an If-Match header with the record's entity tag when you need to prevent overwriting someone else's edit. The server compares the tag you send with the current one and rejects the request if they differ, which turns a silent overwrite into a clear conflict. The same mechanism lets a client retry a failed request safely.
If the updated resource lives at a new URL, or the change alters what a subsequent GET returns, include an ETag or Last-Modified header so clients can cache correctly. Some APIs also return the changed fields only, which keeps large resources cheap to update.
Designing Endpoints Where PATCH Stays Predictable
A partial update endpoint is only as reliable as its rules. Decide these before you publish it:
- Choose one body format and declare it in the Content-Type you accept. Reject anything else with 415.
- State how null behaves. In Merge Patch it removes a field; be sure your database can store or drop that value as intended.
- Decide whether unknown fields are ignored or rejected. Rejecting them catches typos early.
- Define which fields are read-only, such as id and created date, and return 422 if a client tries to change them.
- Keep operations idempotent where possible so a retry after a timeout does not double-apply a change.
- Log the before and after values of changed fields; partial updates are harder to reconstruct from logs than full saves.
One more habit helps: return the full updated record on success when the resource is small. The client then has the current state without a second request, and any field the server normalised, such as trimming spaces or lowercasing an email, is visible immediately.
When PATCH Is the Wrong Choice
Use PATCH when you change a few fields of an existing resource. Reach for PUT when the client holds the whole record and genuinely means to replace it, and when creation with a client-chosen URL is involved.
Avoid PATCH for bulk changes across many records. A single request that touches twenty records is better modelled as its own operation with its own URL, so failures are clear and each change is traceable. Avoid it too when clients cannot reliably know the current state, since a partial update can hide a conflict that a full replacement would surface.
If your API is public, document one worked example for each format you accept. Two short examples remove most support questions, and they show clients exactly which content type to send and what a success response looks like.