Created
October 24, 2016 12:12
-
-
Save theikkila/e2aaa641a1052a0e9110bb1074a1c76c to your computer and use it in GitHub Desktop.
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
(defn auth-middleware [req] | |
(let [auth-headers (get-in req [:headers :auth])] | |
(assoc req :user | |
(if (= auth-headers "secret") | |
{:name "Secret User"} | |
nil)))) | |
(defn random-middleware [req] | |
(assoc req :random "LOL")) | |
(defn controller [req] | |
(let [q (get-in req [:query-params :q]) | |
user (get-in req [:user :name]) | |
hello (str "Hello! " user " your name should be " user)] | |
{:status 201 | |
:headers {:content-type "application/json"} | |
:body {:query hello :random (:random req)}})) | |
(def example-request {:method "POST" | |
:path "/do/something" | |
:query-params {:q "Teemu"} | |
:headers {:auth "secret"} | |
:body ""}) | |
(-> example-request | |
(auth-middleware) | |
(random-middleware) | |
(controller)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment