Is it possible to pass data from exists? to handle-ok ?

41 views
Skip to first unread message

Hussein B.

unread,
Aug 20, 2015, 10:07:51 AM8/20/15
to Liberator
Hi,

For a resource as: /tree/:tree-id/leafs/:leaf-id

I'm using exists? to make sure that the leaf exists. Lets say that is not a cheap operation (DB or whatever).

What I would like to do is to pass the looked up leaf to handle-ok function so the handle-ok isn't going to do the lookup again.

Is it possible?

Thanks.

Philipp Meier

unread,
Aug 20, 2015, 10:17:05 AM8/20/15
to Liberator
That's well possible and the main reason the context exists:

(defresource foo [tree leaf]
  :exists? (fn [ctx] (if-let [leaf (db-lookup tree leaf)] {::leaf leaf}))
  :handle-ok (fn [ctx] (::leaf ctx)))

If you return a map from a decision it's "deep-merged" with the context.


-billy.

Hussein B.

unread,
Aug 21, 2015, 5:48:33 AM8/21/15
to Liberator
That is really cool.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages