We have a requirement to develop a REST API that updates a resource. Including:
- Updating properties values
- Adding\removing properties
Now, we have 2 alternatives:
- Using PUT (following a GET)
- Using PATCH
We know, that the PUT original meaning is the replace an existing resource – so, in order to use PUT, and answer the requirements, we should enable the API consumer, to GET the resource details, and send a PUT request with ALL the details, in order to replace the old resource details. This way, we allow him to update\add\remove properties. But… we would also need to handle concurrent updates. This should probably be done using optimistic-concurrent-control (e.g. using if-modified-since headers).
Alternatively, we can use PATCH – that its intention is to partially update resource. PATCH – with its special syntax – allows updating\adding\removing properties, without the need to supply the full resource details -> so we do not need to GET the resource details first. Here, no need to handle concurrent updates.
We think that the correct solution is PATCH. But… We looked on some well-known REST APIs and we did not see PATCH used widely. Moreover, we saw some (few) articles about problems using PATCH (firewall blocks, clients that does not support it out of the box, etc…). For example:
How to use the PATCH method in HTTP adapters?
How do I stop Apache httpd from rejecting HTTP PATCH requests?
From your experience, should we use the correct thing (PATCH), but risk rejects from consumers? Or should we use the GET+PUT and risk/handle the concurrency issues?
Thanks in advance!