Skip to content

Instantly share code, notes, and snippets.

@vorce
Created Jan 30, 2014
Embed
What would you like to do?
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