Created
June 3, 2012 03:34
-
-
Save candera/2861724 to your computer and use it in GitHub Desktop.
RESTful state machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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