Re: RESTful Toggle

"'Simpson, Robby (GE Energy Management)' [email protected] [rest-discuss]" <[email protected]> Wed, 9 Jul 2014 15:29:59 +0000
Newsgroups gmane.comp.web.services.rest
Message-ID <CFE2D515.3770F%[email protected]>
Hi Nick,

Happy to elaborate.

I'm certainly not heading down a hypothetical route, though I must admit I am interested in sticking close to a principled, clean design.

This particular issue has arisen in the design of home automation systems.  Specifically, I'm working in a standards body (the ZigBee Alliance) that has classically used a binary protocol that does not really adhere to any true architectural design (IMHO).  I've been engaged in work that started in ZigBee and has now moved to IEEE (2030.5) that (attempts to) rigidly stick to a RESTful HTTP design.  One request that has come up is to port toggle switch capability to this standard.  Home automation manufacturers have actually implemented toggle switches this way in the past (see http://zigbee.org/Products/ByStandard/ZigBeeHomeAutomation.aspx).

So, in short, I myself am not manufacturing a specific toggle switch, but rather have been working in a standards body where others have requested the inclusion of toggle switch functionality.  We also have some use cases for a simple button press, which I see as a similar problem.

Thanks,
Robby

From: "Nick Gall [email protected]<mailto:[email protected]> [rest-discuss]" <[email protected]<mailto:[email protected]>>
Reply-To: Nick Gall <[email protected]<mailto:[email protected]>>
Date: Wednesday, July 9, 2014 at 11:14 AM
Cc: Rest List <[email protected]<mailto:[email protected]>>
Subject: Re: [rest-discuss] RESTful Toggle



Robby, I'd like to know more about the real world need for such an API. Sure, mechanical light switches DID work this way, but do home automation systems really offer a "toggle"? I'm trying to imagine why I would ever want to simply change the state of the lighting in my room, without caring if the result was lights on or lights off. I can't.

So are you programming a home automation system? If so, do you really need toggle, given my observation above?

Or is this just a hypothetical question about the generic behavior of toggle and how it maps to REST? If so, then it kind of feels like the perennial, "Can REST do THIS?" questions that skeptics of REST would lob from time to time in the good old REST v WS-STAR WARS days. It kind of reminds me of the old chestnut, "How can I do two-phase commit in REST?"

Or is your need for toggle behavior truly needed in some other actual domain? If so, could you please tell us a bit more about the domain and it's REAL need for toggle behavior. With such context in mind, we can perhaps help you better map it into a RESTful API.

Thanks.

-- Nick

Nick Gall
Phone: +1.781.325.8370
Other Contact Info: http://bit.ly/nickgall


On Tue, Jul 8, 2014 at 5:28 PM, 'Simpson, Robby (GE Energy Management)' [email protected]<mailto:[email protected]> [rest-discuss] <[email protected]<mailto:[email protected]>> wrote:
Hi,


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
"Off."


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?


Any suggestions?


Thanks,
Robby




------------------------------------
Posted by: "Simpson, Robby (GE Energy Management)" <[email protected]<mailto:[email protected]>>
------------------------------------


------------------------------------

Yahoo Groups Links








------------------------------------

------------------------------------


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/rest-discuss/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/rest-discuss/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/