Created
May 6, 2009 19:32
-
-
Save cgrand/107685 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
;; here is roughly what I'd like to write: | |
; an app can simply wrap a handler | |
(app | |
(fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body "<h3>Hello World</h3>"})) | |
; an app can declare routes | |
(app | |
["hello" name] | |
(fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "<h3>Hello " name "</h3>")})) | |
; routes can be nested: | |
(app | |
["hello" &] | |
(app | |
[name] | |
(fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "<h3>Hello " name "</h3>")}))) | |
; params can be parsed/validated | |
(app | |
["by-date" [[year month day] parse-date]] ...) | |
; and hence composed: | |
(def by-name | |
(app | |
[name] | |
(fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "<h3>Hello " name "</h3>")}))) | |
(app | |
["hello" &] by-name | |
["greet" &] by-name) | |
;an app knows about methods: (without any, you get a 405 method Not Allowed) | |
(app | |
:get (fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "GET!")}) | |
:post (fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "POST!")} | |
:any (fn [req] {:status 200 :headers {"Content-Type" "text/html"} | |
:body (str "ANYTHING ELSE!")})) | |
;an app can use existing middlewares (eg from compojure) | |
(app | |
with-multipart | |
(with-session :memory) | |
["account" &] | |
(app | |
[] {:get (show-account (session :user))} | |
["upload-avatar"] {:post (save-upload-avatar (params :avatar-upload))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment