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

The decisions page should provide details about implementing decisions #321

Open
holyjak opened this issue Sep 22, 2021 · 3 comments
Open

Comments

@holyjak
Copy link

holyjak commented Sep 22, 2021

http://clojure-liberator.github.io/liberator/doc/decisions.html should include something like

BTW, where does the source for the page live? I do not see it in this repo.

Implementing a decision

A decision is a (fn [{:keys [request resource] :as context}] ...) that is expected to return a truthy value. In addition, it can also update the context - if the returned value is a map then it is merged into the context, if it is a function than the context is passed through it, if it is a vector then its second element is checked for being a map/function. Example:

(defresource foo
  :allowed-methods [:get]
  :allowed? (fn [{:keys [request resource]}]
              (let [user (my/fetch-user! request)]
                (when (my/authorized? user resource)
                  {::user user})))
  :handle-ok (fn [ctx]
               (log/info "user" (-> ctx ::user :name) "accessed foo")
               (foo/get (:request ctx))))```
@ordnungswidrig
Copy link
Member

This is a very good idea. I'll happily merge a patch if you mind creating a PR. The docs are in the gh-pages branch of the repository, use this branch as the target for your PR.

@holyjak
Copy link
Author

holyjak commented Sep 28, 2021

Done in #322

@holyjak
Copy link
Author

holyjak commented Oct 8, 2021

@ordnungswidrig can we merge #322 and close this? Or do you want any changes? Thank you!

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

No branches or pull requests

2 participants