Last active
August 29, 2015 13:56
-
-
Save peterschwarz/9211799 to your computer and use it in GitHub Desktop.
Hello Session World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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