Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
Created September 24, 2013 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nnarhinen/6691550 to your computer and use it in GitHub Desktop.
Save nnarhinen/6691550 to your computer and use it in GitHub Desktop.
Use sessions with compojure
(ns server.routes
(:use compojure.core
server.views
[ring.middleware.json :only (wrap-json-response)]
ring.middleware.session
[ring.util.response :only (response)]
[hiccup.middleware :only (wrap-base-url)])
(:require [compojure.route :as route]
[compojure.handler :as handler]
[compojure.response :as response]))
(defroutes main-routes
(GET "/count" {session :session}
(let [count (:count session 0)
session (assoc session :count (inc count))]
(->
(response {:foo "Bar", :count (:count session)})
(assoc :session session))))
(route/resources "/")
(route/not-found "Page not found"))
(def app
(-> (handler/site main-routes)
(wrap-base-url)
(wrap-json-response)
(wrap-session)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment