REST - model state transitions -


in rest - revertable delete nice introduction on howto model state changes in rest given. basically, if have resource field status, put new version of resource update status field.

in topic, extend model. have resource can in 2 states: 1 , 2. in contrast simple model described in cited post, there 3 transitions traverse state 1 state 2, instead of one.

my question is: how model state transitions in rest?

i myself cannot come rpc-like post, isn't restian probably:

post http://server/api/x      target_state=2&transition=3 

this changes resource x state 1 state 2 using transition 3.

this isn't limited rest; it's more basic question state machines. state machine should encapsulate of state, if find creating multiple transitions 1 state another, , difference significant, difference must captured in state.

for example, have no home. can move "homeless" state "home" state in 3 ways: can rent one, can buy one, can steal one. 3 transitions "homeless" "home"? not in world of machines. either differences significant, or they're not. if they're not, machine there's no point in making distinction @ all. merely put new status of "home". if are, need expand our concept of state encompass differences. example:

         homeless                     /     |    \       v      |     v possessor <--|---  renter            |    /         \    |   /          v   v  v            owner 

i can move homeless possessor stealing house. if squat on long enough, might become owner. or homeless , rent house, or rent-to-own. or buy 1 outright. 3 paths me "owner" state, use intermediate states represent different transitions.

if want represent "homeless" vs. "in home" (possessor|renter|owner), there's no problem exposing read-only, calculated resource in own right. don't let put/post it, since transition ambiguous. there's no problem keeping history of state transitions additional set of resources, if state significant.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -