On 5 Nov., 22:06, James Reeves <
weavejes...@googlemail.com> wrote:
> On Nov 5, 2:08 pm, Philipp Meier <
phme...@gmail.com> wrote:
>
> > I started a thin library on top of compojure which provides a
> > webmachine-style way of defining RESTful resources. What I have is by
> > no means complete and still growing. However I'd appreciate any
> > feedback.
>
> I think it would be better to make use of middleware in this case. For
> example:
>
> (defroutes hello-resource
> (GET "/"
> (str "Hello (params :who "unknown"))))
>
> (decorate hello-resource
> (wrap-etag (comp :who :route-params))
> (wrap-expiry (constantly 10000))
> (wrap-auth some-auth-function)
> ...)
Great! I thought about something like you outlined, too, but obviously
my compojure-fu was to low. What I miss with the decorators is to pass
along some context. For example if the generation of the etag or
expiry-date is not ultra-light you'd want to re-use the result while
building the body. Is there a way in compojure to do this?
> To make Compojure more RESTful, I'm planning on decoupling the output
> layer from the routes. This would allow you to do this:
>
> (defroutes example
> (GET "/person/name"
> {:name "Fred", :email "
f...@example.com"}))
>
> (decorate example
> wrap-json-output
> wrap-xml-output)
And compojure will negotiate the content-type based on what the output
functions provide? Don't forget that HTTP enables to negotiate the
language, character-set and encoding as well. While character-set and
encoding can be handled transparently by a decorator, the available
languages can only be determined by the output layer.
So the output layer would be at least responsible for
* Providing the content-types it can handle
* Providing the languages it can provide
* Build the actual response
Am I right that the output layer could be specified using decorators
as well, sth. like this:
(defn output-person [req]
(str (({:de "Hallo, " :en "Hello, "} (req :language)) (-> req
params :who "unknown")))
(decorate-output output-person
(wrap-negotiate-languages [:de :en])
Did you start on the implementation yet? Do you plan to branch
compojure or are you going to put it in another library.
-billy.