incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Jacob <a...@opscode.com>
Subject Re: switching between response content type in show? how to trigger html response inst of default xml
Date Sun, 26 Jul 2009 20:54:51 GMT
On Sat, Jul 25, 2009 at 3:22 PM, Chris Anderson<jchris@apache.org> wrote:
> The implementation of respondsWith is built on top of mimeparse.js, my
> port of the Mimeparse library. Mimeparse doesn't have a public method
> to return all the acceptable matches, it only returns the "best". This
> can of course be arbitrary as the protocol allows matches to be equal.
>
> So I'll need to push a change back to the Mimeparse repo to add a
> public method to return the supported content-types sorted by quality
> score.

Yep - at which point it'll be pretty easy to get to the next phase
(where you allow people to override a sane default for picking which
content type to send back when they are equal.)  One other common
thing is that web browsers often have complicated accept headers, but
people usually set the accept header explicitly when using a REST
client.  An easy way to exploit that is to just set the default
preference to be returning html if any of it's content-type
derivatives are present.

> Thanks for pushing back Adam. I've even seen situations where browser
> accept headers were triggering xml feed generation instead of html.
> This isn't fun for new developers, especially as it's triggered by
> some browsers and not others.

Yeah - Accept header parsing is a huge pain to get right, but when you
do, it's glorious.

> You've got me thinking about how I can craft an API that makes all
> this clearer for users, something like:
>
> respondWith("html", function() { ... }");
>
> respondWith("xml", function() { ... }");

Totally - merb's provides api does something similar.

> etc...
>
> The difference between this and the current API is that it gets an
> ordering for users. So the first matching function would be run to
> generate the response. If no functions matched, the first function
> would also be run (or maybe there should an option for strict 406
> errors.)

Well, if the Accept header contains */*, then you get to pick.  If it
doesn't, then it's a 406.

> Still thinking about all this...

I'm holoway on IRC, and I'm almost always there, and I'm super
opinionated (obviously). :)  Feel free to ping me directly if I can be
of any assistance.

Adam

-- 
Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-4759 E: adam@opscode.com

Mime
View raw message