Skip to content

Instantly share code, notes, and snippets.

@orther
Last active August 29, 2015 14:19
Show Gist options
  • Save orther/ecbd6dade505495bf8fc to your computer and use it in GitHub Desktop.
Save orther/ecbd6dade505495bf8fc to your computer and use it in GitHub Desktop.
(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