Instantly share code, notes, and snippets.

@bobo bobo/core.clj
Created Aug 30, 2010

What would you like to do?
(ns SimpleTasks.core
(:use compojure.core
ring.adapter.jetty, ring.middleware.params, ring.middleware.session))
(defn display []
(html [:h1 "hello world!"]))
(defn render-form []
(form-to [:post "/form" ]
"Add task"
(text-field :task)
(submit-button "save"))))
(defn handle-form [params]
{:body (str "stored" (params "task"))
:session {:tasks (params "task")}})
(defn view [session]
(html [:h1 (str "tasks: " (:tasks session))]))
(defroutes myroutes
(GET "/" [] (display))
(GET "/form" [] (render-form))
(GET "/view" {session :session} (view session))
(POST "/form" {params :params} (handle-form params)))
(wrap! myroutes :session)
(defonce server (run-jetty #'myroutes
{:join? false
:port 8080}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment