Differences between revisions 6 and 7
Revision 6 as of 2012-01-05 20:28:05
Size: 1741
Editor: c-24-60-185-198
Comment: adding sag
Revision 7 as of 2013-03-22 18:36:31
Size: 1848
Editor: e181026196
Comment: Added pouchDB
Deletions are marked like this. Additions are marked like this.
Line 50: Line 50:
  * [[http://www.pouchdb.com|Pouchdb.com]] JavaScript library work offline, and sync with CouchDB (Alpha)

We have a new wiki. The migration is not 100% complete. You can help out by moving pages across. This wiki will exist for as long as there are pages left.

The official documentation has moved to http://docs.couchdb.org — The transition is not 100% complete, but http://docs.couchdb.org should be seen as having the latest info. In some cases, the wiki still has some more or older info on certain topics inside CouchDB.

You need to be added to the ContributorsGroup to edit the wiki. But don't worry! Just email any Mailing List or grab us on IRC and let us know your user name.

Getting started with JavaScript and the CouchDB API.

Simple Wrapper

There is a simple JavaScript wrapper around CouchDB included in the distribution. When you install the server it is installed as http://localhost:5984/_utils/script/couch.js. You can see examples of its use in couch_tests.js:

 var nc = {_id:"NC", cities:["Charlotte", "Raleigh"]};
 var ma = {_id:"MA", cities:["Boston", "Lowell", "Worcester", "Cambridge", "Springfield"]};
 var fl = {_id:"FL", cities:["Miami", "Tampa", "Orlando", "Springfield"]};



 var nc_cities = db.open('NC').cities;

Obviously the couch.js API is by no means final since CouchDB itself is still in flux.

Rolling Your Own

CouchDB speaks JSON. JSON means JavaScript Object Notation. CouchDB also speaks Plain Old HTTP, so getting going with JavaScript is a walk in the park with the XML!HttpRequest object:

// instantiate a new XMLHttpRequest object
var req = new XMLHttpRequest()
// Open a GET request to "/all_dbs"
req.open("GET", "/_all_dbs")
// Send nothing as the request body
// Get the response
["some_database", "another_database"]

Going from here is just a matter using the normal CouchDB HttpRestApi to get what you want.

There are numerous javascript libraries out there that wraps up both XML!HttpRequest and JSON in possibly nicer APIs, including:

Getting_started_with_JavaScript (last edited 2013-03-22 18:36:31 by e181026196)