Re: RESTful Toggle

"Jan Algermissen [email protected] [rest-discuss]" <[email protected]> Wed, 9 Jul 2014 14:47:25 +0200
Newsgroups gmane.comp.web.services.rest
Message-ID <[email protected]>
Hi Robby,

On 08 Jul 2014, at 23:28, 'Simpson, Robby (GE Energy Management)' robby.sim=
[email protected] [rest-discuss] <[email protected]> wrote:

> Hi,
>=20
> I've been scratching my head over this one for a while and am hoping I ca=
n
> get some help.
>=20
> Imagine a light switch with one simple resource: /state , where state can
> be "On" or "Off."
>=20
> 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" o=
r
> "Off."
>=20
> Where I'm struggling is with a safe "Toggle" mechanism. That is, if
> /state is "On", change it to "Off" and vice versa.

Mint a resource that represents the =91on=92 state (e.g. an on-flag)

PUT (create) and DELETE the flag using conditional requests:

Create-if-not-exists

PUT /toggles/42?on-flag
If-None-Match: *

delete if exists:
DELETE /toggles/42?on-flag
If-Match: *

HTH,

Jan







>=20
> 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?).
>=20
> Any solution I've looked at thus far seems to violate RESTful principles,
> particularly regarding idempotency. In short, can one safely toggle?
>=20
> Any suggestions?
>=20
> Thanks,
> Robby
>=20
>=20
>=20



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

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


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

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]=20
    [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/