Over a million developers have joined DZone.

CouchDB 2.0 (Developer Preview) With HTTP APIs

DZone 's Guide to

CouchDB 2.0 (Developer Preview) With HTTP APIs

The CouchDB Developer Preview brings all-new clustering technology to the Open Source NoSQL database.

· Database Zone ·
Free Resource


The Apache CouchDB project had announced a Developer Preview release of its CouchDB 2.0. The Developer Preview 2.0 brings all-new clustering technology to the Open Source NoSQL database, enabling a range of big data capabilities that include being able to store, replicate, sync, and process large amounts of data distributed across individual servers, data centers, and geographical regions in any deployment configuration, including private, hybrid, and multi-cloud.

In earlier versions of CouchDB, databases could be replicated across as many individual servers as needed, but each server was limited by vertical scaling. With the clustering introduced in the Developer Preview, databases can now be distributed across many servers, adding horizontal scaling capability to CouchDB. This technology works by borrowing many principles from Amazon's Dynamo paper, and improves the overall performance, durability, and high-availability of large-scale CouchDB deployments.

Other additions in the Developer Preview include a faster database compactor, a faster replicator, easier setup, re-organised code for easier contributions, a global changes feed, and improved test coverage. This version of CouchDB also includes a new Web dashboard admin interface called Fauxton, with improved user experience design, rich query editors, and a management interface for replication. (A screenshot of Fauxton is available at

The Apache CouchDB community encourages feedback as it works towards the 2.0 General Availability release, which is expected early 2015.

To Build

You can follow the steps in here[3] . If you are windows user you can referee my previous post. You can start CouchDB 2.0 (Developer Preview)


The API can be divided into Server, Databases, Documents and Replication. By giving below command we can start 2 nodes in cluster.

dev/run -n 2

cluster couchDB

Servers / nodes

Two node cluster on the ports 15984 and 25984. They represent the endpoints in a two node cluster and you can connect to either one of them to access the full cluster. The backdoor port for 15984 would be 15986 and same way for 25984. Here We are checking the ports of two nodes.

cluster couchDB2


Let create databases. CouchDB is a database management system (DMS) and it can hold multiple databases. So creat database called 'books'

curl -X PUT

cluster couchDB node1

CouchDB replies as 'OK' in JSON so it is created. You can not create a database that already exists therefore we can only have one database called 'books' in one node.

You can view all dbs in you node from below. I have shards that I was testing and I will about shards of CouchDB later.


cluster couchDB node1

You can delete the database by below request. You can see the full request that we have send from CURL and full respond with headers.
curl -vX DELETE

cluster couchDB node1


Documents are CouchDB’s central data structure. Each document has it's ID and it is unique per database. We can choose any string to be the ID

curl -X PUT -d '{"title":"Unbroken: A World War II Story of Survival, Resilience, and Redemption","author":"Laura Hillenbrand"}'

/books/6e4567ed6c29495a567c05947f18d234bb specifies the location of a document inside our books database.

curl -X GET


we can ask CouchDB to give us UUID by
curl -X GET

If we want to update or delete a document, CouchDB expects us to include the _rev field of the revision you wish to change. When CouchDB accepts the change it will generate a new revision number. This mechanism ensures that, in case somebody else made a change without you knowing before you got to request the document update, CouchDB will not accept your update because you are likely to overwrite data you didn’t know existed. Or simplified: whoever saves a change to a document first, wins.

curl -X PUT -d '{"_rev":"1-80d0a1648cce795265cb4f2ba0557a12","ttitle":"Unbroken: A World War II Story of Survival, Resilience, and Redemption","author":"Laura Hillenbrand","published-date":"July 29, 2014"}'



CouchDB replication is a mechanism to synchronize databases. Much like rsync synchronizes two directories locally or over a network, replication synchronizes two databases locally or remotely.

In a simple POST request, you tell CouchDB the source and the target of a replication and CouchDB will figure out which documents and new document revisions are on source that are not yet on target, and will proceed to move the missing documents and revisions over.

curl -X PUT

curl -vX POST -d '{"source":"books","target":"books-replica"}' -H "Content-Type: application/json"

We can mark remote target such as our node 2 as below

curl -vX POST -d '{"source":"books","target":""}' -H "Content-Type: application/json"

Here we can look database details on each node by below command. We can find memory details

curl -X GET
curl -X GET


Those are very basic couchDB APIs.

[1] http://madhukaudantha.blogspot.com/2015/03/couchdb-fauxton-introduction.html
[2] http://madhukaudantha.blogspot.com/2015/03/couchdb-with-fauxton-in-windows-8.html
[3] https://couchdb.apache.org/developer-preview/2.0/


nosql ,couchdb ,http api ,database

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}