Permalink
Browse files

apply ring-json library to automate json

  • Loading branch information...
jflinchbaugh committed Mar 6, 2018
1 parent 5e07160 commit 37d35623d312315f5d74430388da934913751c66
Showing with 26 additions and 14 deletions.
  1. +6 −4 project.clj
  2. +20 −10 src/cheshire_cat/handler.clj
View
@@ -2,10 +2,12 @@
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
[cheshire "5.8.0"]]
:dependencies [
[org.clojure/clojure "1.8.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
[ring/ring-json "0.4.0"]
]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler cheshire-cat.handler/app}
:profiles
@@ -1,19 +1,29 @@
(ns cheshire-cat.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[cheshire.core :as json]))
(:require
[compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[cheshire.core :as json]
[ring.middleware.json :as ring-json]
[ring.util.response :as rr]
)
)
(defroutes app-routes
(GET "/" [] "Hello World")
(GET "/cheshire-cat" [] {
:status 200
:headers {"Content-type" "application/json;charset=utf-8"}
:body (json/generate-string
(GET "/cheshire-cat" []
(rr/response
{
:name "Cheshire Cat"
:status :grinning})})
:status :grinning
}
)
)
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
(-> app-routes
(ring-json/wrap-json-response)
(wrap-defaults site-defaults)
)
)

0 comments on commit 37d3562

Please sign in to comment.