API-13Recommended
Say which format PATCH accepts
Accept PATCH bodies in one documented patch format, and name it in the Content-Type header.
How to do it
Use JSON Merge Patch from RFC 7396 for simple updates, served as application/merge-patch+json. In it, a field set to null is removed and missing fields stay unchanged. Use JSON Patch from RFC 6902 when clients must edit lists. List the formats in the Accept-Patch header, as RFC 5789 describes. Answer 415 to any other type. Apply only the fields a client may change, as Accept only the fields you expect says.
Examples
HTTP example
PATCH /orders/ord_8f2k HTTP/1.1
Content-Type: application/merge-patch+json
If-Match: "v7"
{"note":"Leave at the door","giftWrap":null}
How to check
A PATCH that changes one field leaves every other field unchanged. A PATCH sent as text/plain gets 415 with Accept-Patch.
Sources
Related rules
- APS-21 Accept only the fields you expect in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/requests-and-responses/patch-format">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.