juxt/bidi — pull request #27 by johncowie (2014-09-04 22:20:06+00:00)
Title: Add optional function to make-handler

I really like the simplicity of bidi (versus the macro-y-ness of compojure), but I also wanted to be able to separate the routes from the functions they point to through a lookup. To do this I added an optional function argument to the make-handler function, so if your route map doesn't point to a handler function, then this function can be applied to the result to get one.

My use-case is in the test. I think simply having keywords at the end of the routes is very nice (particularly when using path-for to lookup a route). The optional function then means that when a request is handled, the appropriate handler can be retrieved from a map. E.g.:

```clojure
(def handler-map {:hello (fn [req] {:status 200 :body "Hello Word"})}
(def routes ["/" :hello])
(defn locate-handler [id] (get handler-map id))
(make-handler routes locate-handler)
(path-for routes :hello) ; => "/"
```