Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable keywords as functions as handler #15

Closed
ordnungswidrig opened this issue Jan 17, 2013 · 3 comments
Closed

Enable keywords as functions as handler #15

ordnungswidrig opened this issue Jan 17, 2013 · 3 comments
Milestone

Comments

@ordnungswidrig
Copy link
Member

(defresource ticket-resource
  :method-allowed? (request-method-in :get)
  :available-media-types ["text/plain"]
  :exists? (fn [{{id :id} :params} :request}]
              (if-let [ticket (get-ticket-by-id id)]
                  {::ticket ticket})) ;; associate in context
  :handle-ok ::ticket ;; use the keyword as a function
  :handle-not-found "ticket not found")

Currently does not work because liberator tries to coerce ::ticket to a Representation. It would be nice if it would work exactly like :handle-ok #(::ticket %)

@cddr
Copy link
Contributor

cddr commented Oct 15, 2014

It seems like this already works. At least for :handle-ok. I wrote the following facts/fixtures to prove it to myself. Would you be interested in a PR that adds the test below?

(defresource with-keyword-handler
  :exists? {::important-message "#yolo"}
  :handle-ok ::important-message)

       (fact "keyword handlers should return their entry in the context"
             (with-keyword-handler {:request-method :get})
             => {:headers {"Content-Type" "text/plain;charset=UTF-8"}, :body "#yolo", :status 200})

@ordnungswidrig
Copy link
Member Author

Thanks, but we already have a test at https://github.com/clojure-liberator/liberator/blob/master/test/test_execution_model.clj#L52

This issue was implemented in 46fb458 but not closed.

Thanks for the catch!

@cddr
Copy link
Contributor

cddr commented Oct 16, 2014

No worries. Thanks for pointing out the existing test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants