Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created May 6, 2009 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/107685 to your computer and use it in GitHub Desktop.
Save cgrand/107685 to your computer and use it in GitHub Desktop.
;; 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