You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Chris Anderson <jc...@apache.org> on 2008/12/24 03:15:07 UTC

document forms

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
representation.

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:
http://github.com/jchris/couchdb/tree/templates/share/www/script/couch_tests.js#L2084

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: http://friendpaste.com/5pZcOrLZGkOi1vepapGHso

Chris



-- 
Chris Anderson
http://jchris.mfdz.com

Re: document forms

Posted by Patrick Aljord <pa...@gmail.com>.
It looks great, just a little curiousity, why is it called "forms"? I first
thought it was about html formulars. =)

Re: document forms

Posted by Chris Anderson <jc...@gmail.com>.
>> On Wed, Dec 24, 2008 at 3:51 AM, Jason Davies <ja...@jasondavies.com>
>> wrote:
>>>
>>> I get an empty response (due to internal crash) when attempting to GET a
>>> form for a non-existent document.  Attempting to GET a non-existent form
>>> returns a 404 as expected.
>>>
>>
>> Thanks for the heads up. I'll add a test for that.

I've added this and a couple other error handling cases, and created
form as an Apache branch which you can view online here:

http://svn.apache.org/viewvc/couchdb/branches/form/

I hope this branch doesn't have a very long lifespan, but it seems
like the best way to integrate into trunk where everyone has a chance
to look at it. I think document forms may be almost done, but there is
still the challenge of view forms. I think I'll let that sit for
another (snowy) day.

-- 
Chris Anderson
http://jchris.mfdz.com

Re: document forms

Posted by Damien Katz <da...@apache.org>.
On Dec 24, 2008, at 1:26 PM, Chris Anderson wrote:

> On Wed, Dec 24, 2008 at 3:51 AM, Jason Davies  
> <ja...@jasondavies.com> wrote:
>> I get an empty response (due to internal crash) when attempting to  
>> GET a
>> form for a non-existent document.  Attempting to GET a non-existent  
>> form
>> returns a 404 as expected.
>>
>
> Thanks for the heads up. I'll add a test for that.
>
> I believe it'd be nice to allow requesting an old _rev with a
> ?rev=oldrev parameter. And there are probably more niceties than that
> to work on.
>

I'm thinking this is a bad idea, as it will further encourage using  
the revision system as a VCS. I'm actually thinking of making it  
harder to get the previous rev, the current implementation make it  
easy to misunderstand how things are supposed to work.

-Damien


Re: document forms

Posted by Chris Anderson <jc...@gmail.com>.
On Wed, Dec 24, 2008 at 3:51 AM, Jason Davies <ja...@jasondavies.com> wrote:
> I get an empty response (due to internal crash) when attempting to GET a
> form for a non-existent document.  Attempting to GET a non-existent form
> returns a 404 as expected.
>

Thanks for the heads up. I'll add a test for that.

I believe it'd be nice to allow requesting an old _rev with a
?rev=oldrev parameter. And there are probably more niceties than that
to work on.


-- 
Chris Anderson
http://jchris.mfdz.com

Re: document forms

Posted by Jason Davies <ja...@jasondavies.com>.
Hi Chris,

I like the concept very much, I will give you more feedback once I've  
played with it in depth.  Here are just a couple of implementation  
comments:

On 24 Dec 2008, at 02:15, Chris Anderson wrote:

> 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.

I get an empty response (due to internal crash) when attempting to GET  
a form for a non-existent document.  Attempting to GET a non-existent  
form returns a 404 as expected.

> The diff itself (cleaned up to work against current svn trunk) is
> available here: http://friendpaste.com/5pZcOrLZGkOi1vepapGHso

I get an error when attempting to apply that patch against current svn  
trunk:

   patching file share/www/script/couch_tests.js
   patch: **** malformed patch at line 652: @@ -2058,8 +2307,7 @@

I can clone the git repository fine though.  Git FTW!

Cheers,

Jason