Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(ns example.flash
(:use compojure.core)
(:use ring.util.response)
(:use ring.middleware.session)
(:use ring.middleware.flash)
(:require [compojure.route :as route]))
(defn show-new [flash]
(str "Flash: " flash
"<br/>
<form method='POST' action='/news'>
<input type='submit' value='Success'>
</form>
<form method='POST' action='/newf'>
<input type='submit' value='Error'>
</form>"))
(def flash-success {:flash {:success "Success"}})
(def flash-error {:flash {:error "Failed"}})
(defroutes handler
(GET "/" [] "<h1>Hello World Wide Web!</h1>")
(GET "/new" {flash :flash} (show-new flash))
(POST "/news" {params :params} (merge (redirect "/new") flash-success))
(POST "/newf" {params :params} (merge (redirect "/new") flash-error))
(route/not-found "Page not found"))
(def app (wrap-session (wrap-flash handler)))
(defonce x (future (run-jetty (var app) {:port 8088})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment