Created
October 11, 2012 20:56
-
-
Save jjcomer/3875427 to your computer and use it in GitHub Desktop.
JSON Middleware
This file contains 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- json-request? | |
[req] | |
(if-let [#^String type (:content-type req)] | |
(not (empty? (re-find #"^application/(vnd.+)?json" type))))) | |
(defn wrap-json-params [handler] | |
(fn [req] | |
(if-let [body (and (json-request? req) (:body req))] | |
(let [bstr (slurp body) | |
json-params (parse-string bstr) | |
req* (assoc req | |
:json-params json-params | |
:params (merge (:params req) json-params))] | |
(handler req*)) | |
(handler req)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment