Created
January 30, 2014 21:02
-
-
Save vorce/8718599 to your computer and use it in GitHub Desktop.
Compojure example
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 webpoints.handler | |
(:use compojure.core) | |
(:require [compojure.handler :as handler] | |
[compojure.route :as route])) | |
;; Our "database" | |
(def mydb (atom {})) | |
(defn set-points | |
"Update hostname with points" | |
[hostname points] | |
(swap! mydb conj {hostname points})) | |
(defroutes app-routes | |
(GET "/:ns/:hostname" [ns hostname] | |
(str "{ " hostname ": " (get @mydb hostname 0) " }")) | |
(GET "/:hostname" [hostname] | |
(str "{ " hostname ": " (get @mydb hostname 0) " }")) | |
(PUT "/:ns/:hostname/:points" [ns hostname points] | |
(set-points hostname points) | |
(str "{ " ns "/" hostname ": " points " }")) | |
(route/resources "/") | |
(route/not-found "Not Found")) | |
(def app | |
(handler/site app-routes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment