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

decision: docs on how to implement one #322

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ Liberator supports a whole lot of decisions points. Some of them are
needed for next to every resource definition. Others are seldom used
or there is no other sensible implementation.

## 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:

```clojure
(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))))
```

## Typical decision points for resource implementors

The following decisions points will be typically specified depending
Expand Down