couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Midgley <scie...@misuse.org>
Subject Re: ANN: Fermata, a "native" JavaScript library for CouchDB (and everything else)
Date Fri, 19 Aug 2011 01:22:34 GMT
Hi Nate,

Looks really interesting and I'll be interested to play with it. You
asked about python and CouchDB - our project
(www.learningregistry.org) is using a python middle tier and couchdb
backend.

I'm particularly interested in Fermata as you mention you're working
on OAUTH. If you start to work on crypto signatures (part of OAUTH 1)
please ping me -- we use JSON crypto signing for our couch docs, but
currently don't have a way to do signing in javascript (we wrote utils
for php and python so far). It would be a big deal if we had a way to
do that from Javascript as it would permit client-side crypto, but
that seems to be a hard problem until projects like "verified email"
from Mozilla get further off the ground..

Off topic, so ping me at steve.midgley@ed.gov if you want to chat
about that issue at all.

Thanks for the contribution!
Steve

On Sat, Aug 13, 2011 at 12:29 AM, Nathan Vander Wilt
<nate-lists@calftrail.com> wrote:
> I was given some encouragement at CouchConf to announce my little REST library that's
been working beautifully for CouchDB clients (and more):
> https://github.com/andyet/fermata (single <script> include with no compile, and/or
`npm install fermata`)
>
>
> Why did I bother building yet another JavaScipt HTTP library? I grew tired of building
URL strings like `var url = "http://" + myServer + '/' + myApp + "_view/by_date?reduce=false&startkey="
+ encodeURIComponent(JSON.stringify([2001,1])) + "&limit=" + myLimit` — and then this
spring I finally noticed that JavaScript's object/method syntax matches REST so much better
than passing strings/dictionaries to functions like `$.ajax()`.
>
> With Fermata it's really easy to access CouchDB from a browser:
>
>    var photoDB = fermata.api({url:"http://localhost:5984"})('photos');
>    var photosIndexed = photoDB(['_design/shutterstem', '_view']);
>
>    photosIndexed('by_date')({group_level:3}).get(function (err,data) {
>        console.log(data.rows);
>        // ...
>    });
>
>    photosIndexed('by_date')({reduce:false, limit:500, include_docs:true}).get(function
(e,d) {
>        var thumbs = d3.select('#content').selectAll('.frame').data(d.rows);
>        thumbs.enter().append('div').classed('frame', true).append('img').classed('photo',
true)
>            .attr('src', function (d) { return photoDB([d.id, 'thumbnail/64.jpg'])();
});
>    });
>
> In node.js the syntax is even cleaner, thanks to Harmony Proxy objects:
>
>    var myCouch = fermata.api({url:"http://localhost:5984"});
>    var indexedPhotos = myCouch.photos[appName]._view;
>
>    indexedPhotos.by_date({reduce:false, $startkey=[2011,1], $endkey=[2012]}).get(function
(e,d) { console.log(d); });
>
> Of course the "broswer" syntax works in node.js server code too, but it's pretty fun
to pretend that any REST API is just a local JavaScript object. (The dot syntax does actually
work in Firefox and soon Chrome, but for clientside or mixed code I recommend sticking to
parentheses for compatibility.) My teammates at @andyet keep encouraging me that Fermata's
subtle differences really are a big deal in practice: we can assign, extend and access URLs
throughout our code as if they were (virtual) nested JavaScript objects.
>
> I'm currently working on plugin support (for sending XML, OAuth signatures, etc.) but
that's getting off-topic for this list: Fermata already works great with CouchDB and I hope
some of you will find it as useful as we have. Would love to hear your feedback!
>
> regards,
> -natevw
>
> p.s. are many people using CouchDB from Python? ;-)

Mime
View raw message