         datemo.arb)
   (:require [clojure.edn :as edn]
             [compojure.route :as route]
-            [compojure.handler :as handler]
-            [ring.middleware.json :refer [wrap-json-response]]
+            [ring.middleware.json :refer :all]
             [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
             [datomic.api :as d]))
 


(defroutes app-routes
  (GET "/" [] {:body {:_links {:documents {:href "/docs"}}}})
  (POST "/documents" [doc-string] (post-doc doc-string))
  (route/not-found "Not found"))

(def app
  (-> app-routes
      (wrap-json-response)
      (wrap-defaults api-defaults)))


  (edn/read-string {:readers *data-readers*} (prn-str edn)))

(defn get-doc [eid]
  (pprint (type eid))
  (let [doc-tx (d/pull (d/db conn) '[*] eid)
        doc-html (tx->html doc-tx)]
    (pprint doc-tx)
    {:status 200
     :headers {"Content-Type" "application/hal+json; charset=utf-8"}
     :body doc-html}))

(defn post-doc [doc-string]
 (let [tx (-> (html->tx doc-string) (add-tempid) (edn->clj))
       [eid db-after] (save-arb-tx tx)
       tx-from-db (d/pull db-after '[*] eid)
       html (-> tx-from-db (tx->arb) (arb->hiccup) (html))]
   (pprint (type eid))
   {:status 201
    :headers {"Content-Type" "application/hal+json; charset=utf-8"}
    :body {:_links {:self (apply str "/documents/" (str eid))}
