Skip to content

Instantly share code, notes, and snippets.

@peterschwarz
Last active August 29, 2015 13:56
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 peterschwarz/9211799 to your computer and use it in GitHub Desktop.
Save peterschwarz/9211799 to your computer and use it in GitHub Desktop.
Hello Session World
(ns hello-world.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]
[ring.util.response :as resp]
[clojure.data.json :as json]))
(defn generate-response [data & [status]]
{:status (or status 200)
:body (str "<div>Hello <strong>" (:hello data) "</strong></div><div>We seen you <em>" (inc (:count data)) "</em> time(s)</div>")
})
(defn handler
[session name]
(let [count (:count session 0)]
(merge
(generate-response {:hello name
:count count})
{:session (assoc session :count (inc count))})))
(defroutes app-routes
(GET "/name/" {session :session} (handler session "World"))
(GET "/name/:name" [name :as {session :session}] (handler session name))
(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