Skip to content

Instantly share code, notes, and snippets.

@candera
Created June 3, 2012 03:34
Show Gist options
  • Save candera/2861724 to your computer and use it in GitHub Desktop.
Save candera/2861724 to your computer and use it in GitHub Desktop.
RESTful state machines
(defn update [state event-name]
;; current state id | event-name | action
;;
(match [(:status state) event-name]
[:waiting :prepare] #(assoc state :foo f3)
[:ready :delete] #(assoc state :bar 19)
[_ _] (throw (ex-info "Boom: roasted" {:reason :invalid-transition :event-name event-name}))
))
(def s (atom {}))
(defn handler [req]
(swap! s update http-method arg)
)
GET /checkin-process/1 ;; returns current state
POST /checkin=process/1/event ;; changes state (or error)
{:event checkin
:ticket-num 1234}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment