cURL: Your Command Line Friend

Curl is a lightweight command-line tool for transferring data to or from a server using various protocols such as HTTP, HTTPS, and FTP. CURL is a command line tool available on Unix, Linux, Mac OS X and Windows and many other platforms.
The HTTP protocol will be easily accessed using the cURL command-line and therefore an ideal method of interacting with CouchDB over HTTP REST API.

For example, the most basic use of curl is to simply pass it a URL as an argument, and by default it will issue an HTTP GET request to the URL supplied. In this example, the cURL utility returns the source code of the requested page. It displays this code on the terminal window.


cURL Utility Options

You can see various options in cURL utility help.

$ curl --help
Usage: curl [options...] < url >
Options: (H) means HTTP/HTTPS only, (F) means FTP only
--anyauth Pick "any" authentication method (H)
-a/--append Append to target file when uploading (F/SFTP)
--basic Use HTTP Basic Authentication (H)
--cacert < file > CA certificate to verify peer against (SSL)
-d/--data < data > HTTP POST data (H)
--data-ascii < data > HTTP POST ASCII data (H)
--data-binary < data > HTTP POST binary data (H)
--data-urlencode < name=data/name@filename > HTTP POST data
urlencoded (H)
--delegation STRING GSS-API delegation permission
--digest Use HTTP Digest Authentication (H)
--disable-eprt Inhibit using EPRT or LPRT (F)
--disable-epsv Inhibit using EPSV (F)
-F/--form < name=content > Specify HTTP multipart POST data (H)
--form-string < name=string > Specify HTTP multipart POST data (H)
--ftp-account < data > Account data to send when requested by server
--ftp-alternative-to-user < cmd > String to replace "USER [name]" (F)
--ftp-create-dirs Create the remote dirs if not present (F)
--ftp-method [multi cwd/no cwd/single cwd] Control CWD usage (F)
--ftp-pasv Use PASV/EPSV instead of PORT (F)
-G/--get Send the -d data with a HTTP GET (H)
-H/--header < line > Custom header to pass to server (H)
-I/--head Show document info only
-h/--help This help text
--hostpubmd5 < md5 > Hex encoded MD5 string of the host public key.
-0/--http1.0 Use HTTP 1.0 (H)
--ignore-content-length Ignore the HTTP Content-Length header
-i/--include Include protocol headers in the output (H/F)
-M/--manual Display the full manual
-o/--output < file > Write output to < file > instead of stdout
--pass < pass > Pass phrase for the private key (SSL/SSH)
--post301 Do not switch to GET after following a 301
redirect (H)
--post302 Do not switch to GET after following a 302
redirect (H)
-O/--remote-name Write output to a file named as the remote file
--remote-name-all Use the remote file name for all URLs
-R/--remote-time Set the remote file's time on the local output
-X/--request < command > Specify request command to use
--retry < num > Retry request < num > times if transient problems
--retry-delay < seconds > When retrying, wait this many seconds
between each
--retry-max-time < seconds > Retry only within this period
-T/--upload-file < file > Transfer < file > to remote site
--url < URL > Set URL to work with
-B/--use-ascii Use ASCII/text transfer

Three options are very important :-

-X flag :- The -X flag allows you to tell CouchDB which HTTP request method you want to use.
This is important because the HTTP request method will define what exactly the CouchDB server will do (for example, GET retrieves, PUT creates/ modifies, and DELETE destroys).

-H flag :- This allows you to define HTTP headers in your requests to the CouchDB server. When you create documents in CouchDB, you define your documents in JSON and send this JSON data to the server.
Unfortunately, older versions of the CouchDB server have no way of knowing what type of content this is unless you explicitly tell it. Luckily, you can use the -H flag and pass the string Content-Type: application/json which does the same.

-d flag :- This allows you to include data (the message part of the HTTP request) when communicating with the CouchDB server.
This is essential when you want to create meaningful documents or make any changes to existing documents. You will be using the -d flag to send your JSON document definitions and JavaScript view definitions to CouchDB.

Visit :


* You must be logged in to add comment.