Created
August 9, 2016 19:19
-
-
Save MiyamotoAkira/042dae266584936d8c56a8933158de6a to your computer and use it in GitHub Desktop.
Simple Liberator application
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
(ns libtest2.core | |
(:require [liberator.core :refer [defresource]] | |
[liberator.dev :refer [wrap-trace]] | |
[compojure.core :refer [defroutes ANY]] | |
[clojure.data.json :as json] | |
[clojure.java.io :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