CouchDB command-line tool to allow shortened curl commands without putting username/password in your command-line history
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

ccurl - 'couchdb curl'

If you use CouchDB, then you can access everything using curl. The trouble is, that it if you are using an authenticated, hosted service such as Cloudant's, then your credentials appear on your command-line history and there is a lot of typing. e.g.

  curl ''

With ccurl, this becomes:

  ccurl /database/12345678

Or adding a document with curl:

  curl -X POST -H 'Content-type:application/json' '' -d'{"a":1,"b":2}'

With ccurl, this becomes:

  ccurl -X POST /database -d'{"a":1,"b":2}'


ccurl required Node.js (and npm). Simply type:

  npm install -g ccurl

Storing your credentials

Your CouchDB credentials are taken from an environment variable "COUCH_URL". This can be set in your console with

  export COUCH_URL=""

or this line can be added to your "/.bashrc" or "/.bash_profile" file.

If you don't want credentials stored in your command-line history, you can set an environment variable by extracting the credentials from a file e.g.

export COUCH_URL=`cat ~/.ibm/cloudant.json | jq -r .url`

where ~/.ibm/cloudant.json is a JSON file that is readable only by my user containing the Cloudant service credentials.

Using ccurl

  • all command-line switches are passed through to curl
  • instead of passing through a full url, pass through a relative url
  • if the url is omitted, then a relative url of "/" is assumed
  • the content-type of 'application-json' is added for you if you don't already provide a content type


Add a database

  > ccurl -X PUT /newdatabase

Add a document

  > ccurl -X POST /newdatabase -d'{"a":1,"b":2}'

Get a document

  > ccurl /newdatabase/005fa466b4f690ccad7b4d194f071bbe

Get ten documents

  > ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' 

Remove a database

  > ccurl -X DELETE /newdatabase

Other curl command-line parameters work too

  ccurl -h
  ccurl -v

Using ccurl with jq

jq is a command-line json utility, and as ccurl returns JSON, it can be piped in-line to colour the JSON:

 ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' | jq '.total_rows'

or to process or select the data:

 ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' | jq '.'