Last active
December 26, 2015 05:09
-
-
Save josephwilk/7098902 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
;Thought: Clojure destructing not supporting pattern matching means Compojure routes mix | |
; route matching and data extraction. Hence you validate within a route (since you want the extracted data). | |
; | |
; Route matching should support matching on the properties of the extracted data. | |
; A route is just a function and I want Erlang style guard statements. | |
;Now | |
(defroutes app | |
(GET "/impression/:x" [x] (when (valid? x) {:body "Woo hoo" :status 200})) | |
(ANY "*" {:status 404 :body "Not found"})) | |
;Seperate data validation pattern match | |
(defroutes app | |
(GET "/impression/:x" [x #(valid? %)] {:body "Woo hoo" :status 200})) | |
(ANY "*" {:status 404 :body "Not found"})) | |
;Wrap outer route... Less pretty | |
(defroutes app | |
(when (valid? (:x params) (GET "/impression/:x" [x] {:body "Woo hoo" :status 200}))) | |
(ANY "*" {:status 404 :body "Not found"})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment