Skip to content

Instantly share code, notes, and snippets.

@josephwilk
Last active December 26, 2015 05:09
Show Gist options
  • Save josephwilk/7098902 to your computer and use it in GitHub Desktop.
Save josephwilk/7098902 to your computer and use it in GitHub Desktop.
;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