Last active
August 29, 2015 14:19
-
-
Save orther/ecbd6dade505495bf8fc 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
(def ops | |
{"+" + | |
"-" - | |
"*" * | |
":" /}) | |
;; calc request handler and proof the app's in clojure jerk | |
(defn calc [req] | |
(let [a (Integer. (get-in req [:route-params :a])) | |
b (Integer. (get-in req [:route-params :b])) | |
op (get-in req [:route-params :op]) | |
f (get ops op)] | |
(if f | |
{:status 200 | |
:body (str (f a b)) | |
:headers {}} | |
{:status 404 | |
:body (str "Unknown operator: " op) | |
:headers {}}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment