Skip to content

Instantly share code, notes, and snippets.

@vorce
Created January 30, 2014 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vorce/8718599 to your computer and use it in GitHub Desktop.
Save vorce/8718599 to your computer and use it in GitHub Desktop.
Compojure example
(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