Context
I have a REST API where several clients (applications) can update the state of a resource using PUT. For example, this resource is a lamp that you can turn on ONor OFF.
This resource is also automatically updated by the system when it detects that a power failure has occurred, resulting in the lamp being in a state BROKEN. I want to distinguish between BROKENand OFF, the lamp BROKENcannot turn into ON!
Problem
For this I use a method PUT, something likePUT http://address:port/my_lamp { "state": "ON"}
But I'm not sure if I respect the property of the idempotent method PUT. In fact, I have 3 cases:
- The lamp
ON. The above code results in a state ON. - The lamp
ON. The above code leads to a state ON.... cool! At the moment, idempotency remains :-)! - The lamp
BROKEN. The above code results in an error like503 Service Unavailable
Question
I am not sure to understand the concept of idempotency correctly. Believe me, I read a lot about this, but still a little confused.
In my understanding, several PUTalways lead to the same state of the resource: in my case it is not guaranteed due toBROKEN
But I could also understand this in a different way: several PUTalways lead to the same side effect: it is guaranteed that my request either performs the conversion ONor nothing (for the case BROKEN, it already was).
EDIT:
I mean: the only side effect is to turn the ONlamp on, which is guaranteed (it either turns on or does nothing here)See here: Is REST DELETE really an idempotent?
Which one is correct? Depending on the understanding, my REST API provides idempotency or not ...
EDIT2:
From the definition of W3CMethods can also have the βidempotenceβ property in that ( except for errors or problems with expiration ) the side effects of N> 0 identical requests are the same as for a single request.
Can I assume that it is a mistake to turn on the ONlamp when it is BROKEN?
source
share