Chapter 2 · Practice 3 of 4
Use PUT to replace and PATCH to change part of a resource
Why it matters
The difference matters because fields a client omits mean different things:
PUTsends the complete new representation. A field left out is removed or reset to its default.PATCHsends only the changes. Fields left out stay as they are.
For PATCH bodies, pick a defined format instead of inventing one:
| Format | Media type | Good for |
|---|---|---|
| JSON Merge Patch (RFC 7396) | application/merge-patch+json | Simple object updates; null deletes a field |
| JSON Patch (RFC 6902) | application/json-patch+json | Precise operations on arrays and nested paths |
Most APIs only need JSON Merge Patch. Whichever you choose, a client that sends {"email": "new@example.com"} with PATCH must not wipe the rest of the profile.
Example
PATCH /customers/3
Content-Type: application/merge-patch+json
{ "email": "new@example.com", "phone": null }