Created
May 8, 2014 21:53
-
-
Save Quantisan/a8208d3037eebd2e85a6 to your computer and use it in GitHub Desktop.
clojure restful server library idea with Graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://scott.mn/2014/01/26/first_thoughts_on_liberator_clojure/ | |
(defn blog-post-resource [request id] | |
{:authorized? | |
(fnk [logged-in-user request] | |
(or logged-in-user | |
(= (:method request) :get))) | |
:allowed? | |
(fnk [logged-in-user author request] | |
(or (= author logged-in-user) | |
(= (:method request) get))) | |
:author | |
(fnk [id] | |
(:author (lookup-blog-post id))) | |
:logged-in-user | |
(fnk [specified-credentials] | |
(let [[user pass] specified-credentials] | |
(when (password-correct? user pass) | |
user))) | |
:specified-credentials | |
(fnk [request] | |
(when-let [auth-header (get-in ctx [:request :headers | |
"authorization"])] | |
(if-let [creds (parse-basic-auth auth-header)] | |
creds | |
(throw (http-error 400 "Couldn't parse authorization header"))))) | |
...) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment