I have an issue with implementing Idempotent operation in Put.
There is Put
request which updates a field in a rest API resource.
But to implement Idempotency every repeated request should result in same state of the object.
We use a database
what happens if an error occurs. Now does this mean Idempotency
is lost? if not
Now going by the same defintion - If we have a conditional status change in a rest API on a field .eg) status field.
If the logic is to update the status field only if the parent property field locked==false
, we can throw an exception saying 'BusinessLogic exception cannot update status'
So in theory we have two operations we have similar situation:
question:
How do you implement error handling based idempotency for put? and if error handling is OK does this mean even business logics could be made idempotency Put
?
It may help to review the relevant definition of idempotent
We use a database what happens if an error occurs. Now does this mean Idempotency is lost?
Idempotency is not lost. Idempotent doesn't promise that every request will succeed; it only means that any loss of property that occurs because the server received multiple copies of the request is the fault of the server.
does this mean even business logics could be made idempotency Put?
Yes. You can do this in one of two ways: by designing your domain application protocol so that the requests are inherently idempotent; or by using conditional requests to describe the "before" state that the request is intending to change.