Skip to content

Instantly share code, notes, and snippets.

@weavejester
Created October 2, 2010 22:22
Show Gist options
  • Save weavejester/608048 to your computer and use it in GitHub Desktop.
Save weavejester/608048 to your computer and use it in GitHub Desktop.
;; When executed, this file will run a basic web server
;; on http://localhost:8080, which will tell you how many
;; times you have visited the page.
(ns ring.example.session
(:use ring.middleware.session
ring.util.response
ring.adapter.jetty))
(defn handler [{session :session, uri :uri}]
(let [n (session :n 1)]
(if (= uri "/")
(-> (response (str "You have visited " n " times"))
(content-type "text/plain")
(assoc-in [:session :n] (inc n)))
(-> (response "Page not found")
(status 404)))))
(def app
(-> handler wrap-session))
(run-jetty app {:port 8080})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment