Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
;; 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
(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