Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Liberator application
(ns libtest2.core
(:require [liberator.core :refer [defresource]]
[ :refer [wrap-trace]]
[compojure.core :refer [defroutes ANY]]
[ :as json]
[ :as io]))
(defonce appointments (ref []))
(defresource handle-appointments []
:allowed-methods [:post :get]
:available-media-types ["application/json"]
:post! (fn [ctx] (let [body (get-in ctx [:request :body])
converted (slurp (io/reader body))
data (json/read-str converted :key-fn keyword)]
(dosync (alter appointments conj data))))
:handle-ok (fn [_] (json/write-str @appointments)))
(defroutes app
(ANY "/appointments" [] (handle-appointments)))
(def handler
(-> app
(wrap-trace :header :ui)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment