CouchDB Curl

To communicate with CouchDB one can either choose:

  • CouchDB Curl
  • CouchDB Fauxton

But to communicate with the CouchDB database to transfer data from or to a server, CouchDB Curl utility is needed. It is a command-line utility. It thus accesses the HTTP protocol straight away from the command line. It uses protocols like HTTP, HTTPS, FTP, FTPS, TFTP, DICT, TELNET, LDAP or FILE for communication. Being designed to work without user interaction it offers many useful tricks. Some of the tricks include proxy support, user authentication, SSL (https:) connections, cookies, FTP upload, HTTP post and file transfer resume. All the popular operating systems like  UNIX, Linux, Mac OS X and Windows supports the Curl utility.

 

To use Curl Utility:

Use the curl command followed by the desired website address.

For example:

curl https://www.w3schools.blog

 

 Curl Utility Options:

The Curl Utility Options can be checked at Curl utility help.

$ curl ?help 

 

Popular Curl Utility Options used by CouchDB are:

-X flag:

It facilitates the users to specify a request method like the GET, POST and PUT while communicating with an HTTP server, to override the default method i.e, the GET method. It also facilitates the users to specify the FTP command while communicating with an FTP server, to override the default command i.e, the LIST command.

-H flag:

It defines a custom header to pass on to the server. For example, a “content-type” header to define the type of content of the file to be uploaded.

-d flag:

It sends data along with the HTTP POST request to the server.

-o flag:

It facilitates the writing of the output of the request to a file.

For example:

curl -o example.html www.w3schools.com/index.html 

After the execution of the above command, the source code of the homepage of example_site.com will be taken, a file named example.com will be created and the output will be saved in the  example.html file.

-O flag:

It also facilitates the writing of the output of the request to a file, similar to the -o flag, but unlike the -o flag, it creates a new file with the same name as the requested URL. The source code of the requested URL will be then copied to the file created.

For example:

curl -O www.w3schools.com/index.html 

 

Hello CouchDB Example:

To access the CouchDB’s homepage one can either:

  1. Use the URL at browser.
  2. Use the command prompt.

To access the CouchDB’s homepage follow the below steps:

  • Ensure the successful installation of CouchDB in the Linux environment.
  • Send a get request to the CouchDB instance to access CouchDB’s homepage:
curl http://127.0.0.1:5984/