Skip to content

Instantly share code, notes, and snippets.

@rawburt
Created March 5, 2010 00:48
Show Gist options
  • Save rawburt/322335 to your computer and use it in GitHub Desktop.
Save rawburt/322335 to your computer and use it in GitHub Desktop.
(ns shoutbox
(:use compojure
somnium.congomongo))
(mongo! :db "shoutbox")
(defn save-shout [s]
(insert! :shouts
{:text s}))
(defn shout-div [s]
[:div (s :text)])
(defn new-shout [s]
(do (save-shout s)
(redirect-to "/")))
(defn shouts-page []
(html
(doctype :html4)
[:html
[:head
[:title "shoutbox"]]
[:body
[:div#main
(form-to [:post "/"]
(text-field :shout)
(submit-button "shout it"))
[:div#shouts
(map shout-div (fetch :shouts))]]]]))
(defroutes webservice
(GET "/"
(shouts-page))
(POST "/"
(new-shout (:shout params))))
(run-server {:port 8080}
"/*" (servlet webservice))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment