couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject document forms
Date Wed, 24 Dec 2008 02:15:07 GMT
Couch devs,

I've been working on a new feature (based on Damien's specification)
called forms. It's a little like action.js, but with decent
performance and caching characteristics. The upshot is that it allows
you to generate HTML (or other) output based on a single document.
There will be forms for views, with a similar concept, but they aren't
part of this patch.

Forms are defined in design documents, as an object under the key
"forms". Each form is a function from a document and a request, to the
output. Form responses have etags based on the form function, the
document, and the Accept headers as sent by the client. This ensures
that an HTML representation will have a different Etag from an Atom

I've also added a helper function called respondWith() to main.js, so
that you can easily switch based on client requests. The best example
code at this point is in couch_tests.js. Here I've linked to the line
where respondWith() is invoked:

Comments about the API and implementation welcome. I think this code
is fairly solid, but I'd like to put a few eyes on it before it goes
into trunk. One thing that is known to be missing, is there is no way
to return direct binary from a form (eg have a form generate an
image/png from a document). This will probably involve just a little
bit of base64 work and the right conventions.

The diff itself (cleaned up to work against current svn trunk) is
available here:


Chris Anderson

View raw message