Short answer: it doesn’t!
Long answer: most likely you did not the declare post!
action
as a function but as a value. Due to the exact details of the
defresource
macro expansion, the form used as the value is
evaluated at unexpected times.
(def x (atom 0))
(defresource wrong
:post! (swap! x inc) ;; this is the bug
:handle-ok (fn [_] (format "The counter is %d" @x)))
(defresource right
:post! (fn [_] (swap! x inc) ;; this is right
:handle-ok (fn [_] (format "The counter is %d" @x)))
If you want to understand the glory details, macroexpand both forms and reason on the lexical scopes.
Add :post
to the list at :allowed-methods
(defresource post-me-harder
:allowed-methods [:get :post])
There weren’t that many questions that came up frequently. To get support quickly, please post your question to our Google Group.