You can take a look at https://github.com/ngrunwald/ring-middleware-format
which tries to handle content negociation only in a sane and flexible way
for REST api.
On Wednesday, November 5, 2014 2:47:02 PM UTC+1, Miguel Ping wrote:
>
> Hi all,
>
> What's the best way to do content-negotiation on compojure-based web
> frameworks? I know liberator deals with it in a special way, I was
> wondering if is there anything out there to deal with it like rails does.
> Right now I have a big cond:
>
> (defn handle-home [req]
> (let [content-type (-> (clojure.walk/keywordize-keys req) :headers
> :content-type)]
> (cond (empty? content-type)
> (home-page) ;renders selmer
>
> (= "application/json" content-type)
> (generate-string (db/get-messages)) ;cheshire json generation
>
> :else
> {:status 415 :body "unavailable-content-type"})))
>
> But I'm pretty sure there's a more idiomatic way of defining resources.
> I'd like a way to just return a hash, and according to content-type either
> render an html (through selmer, whatever) or a json from that map.
> I'm sure this is pretty easy with clojure but I'm still quite new to it.
> I'd like to see how you guys are dealing with this.
> I'm trying luminus right now but I'm guessing this is the same for any
> compojure-based routing.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.