19690Re: [rest-discuss] RESTful Toggle
- Jul 9, 2014An upgrade to that would be to override with new OPTION:BANK for an array of those kind of toggles.[This forward-looking statement is intentional.]
On Wed, Jul 9, 2014 at 2:44 PM, Jonathan Ballard <dzonatas@...> wrote:It may require another resource. Move/Swap/Redirect the two states (on and off) based on current state rather than one specific state that has no mechanism itself for toggle. It depends on how persistent and concurrent you want the two states.Solution:POST /state/onPOST /state/offPUT /state/toggleDELETE /stateReturns semantics for redirected or moved resources. Override with new OPTION:TOGGLE.On Wed, Jul 9, 2014 at 6:06 AM, Keith P Hassen keith.hassen@... [rest-discuss] <firstname.lastname@example.org> wrote:You could implement a POST operation that simply flips the state, whatever it is. If you implement PUT, the request should be idempotent but it's unclear if that's what you intend here. Protecting against the kind of race conditions you mention is usually performed with conditional requests (If-Match, If-None-Match, etc).KOn Tue, Jul 8, 2014 at 5:28 PM, 'Simpson, Robby (GE Energy Management)' robby.simpson@... [rest-discuss] <email@example.com> wrote:
I've been scratching my head over this one for a while and am hoping I can
get some help.
Imagine a light switch with one simple resource: /state , where state can
be "On" or "Off."
One can PUT to /state , changing /state to either "On" or "Off."
Similarly, a GET to /state will tell you if the light is currently "On" or
Where I'm struggling is with a safe "Toggle" mechanism. That is, if
/state is "On", change it to "Off" and vice versa.
I understand that one solution would be to simply perform a GET on /state
and then PUT the opposite. However, I am concerned with both the overhead
and latency this entails as well as the potential for a race condition
(what if /state changes between the GET and the PUT?).
Any solution I've looked at thus far seems to violate RESTful principles,
particularly regarding idempotency. In short, can one safely toggle?
- << Previous post in topic Next post in topic >>