Created
March 5, 2010 00:48
-
-
Save rawburt/322335 to your computer and use it in GitHub Desktop.
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 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