CouchDB - Curl & Futon
CouchDB - Curl & Futon
It is a tool to transfer data from or to a server, using one of the supported protocols (HTTP,
HTTPS, FTP, FTPS, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work
without user interaction. cURL offers a busload of useful tricks like proxy support, user
authentication, ftp upload, HTTP post, SSL (https:) connections, cookies, file transfer
resume and more.
The cURL utility is available in operating systems such as UNIX, Linux, Mac OS X and
Windows. It is a command line utility using which user can access HTTP protocol straight
away from the command line. This chapter teaches you how to use cURL utility.
curl www.tutorialspoint.com/
By default, the cURL utility returns the source code of the requested page. It displays this
code on the terminal window.
Explore our latest online courses and learn new skills at your own pace. Enroll and become
a certified expert to boost your career.
$ 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)
While communicating with CouchDB, certain options of cURL utility were extensively used.
Following are the brief descriptions of some important options of cURL utility including those
used by CouchDB.
-X flag
(HTTP) Specifies a custom request method used when communicating with the HTTP server.
The specified request is used instead of the method otherwise used (which defaults to GET).
Read the HTTP 1.1 specification for details and explanations.
(FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with ftp.
-H
(HTTP) Extra header is used when getting a web page. Note that if you add a custom header
that has the same name as one of the internal ones cURL would use, your externally set
header will be used instead of the internal one. This allows you to make even trickier work
than cURL would normally do. You should not replace internally set headers without perfectly
knowing what you’re doing. Replacing an internal header with the one without content on
the right side of the colon, will prevent that header from appearing.
cURL assures that each header you add/replace get sent with the proper end of line marker.
Neither you should add that as a part of the header content nor add newlines or carriage
returns to disorder things.
-d flag
Using this flag of cURL, you can send data along with the HTTP POST request to the server,
as if it was filled by the user in the form and submitted.
Example
Suppose there is a website and you want to login into it or send some data to the website
using –d flag of cURL utility as shown below.
-o flag
Using this flag, cURL writes the output of the request to a file.
Example
This gets the source code of the homepage of tutorialspoint.com, creates a file named
example.com and saves the output in the file named example.html.
-O
This flag is similar to –o, the only difference is with this flag, a new file with the same name
as the requested url was created, and the source code of the requested url will be copied to
it.
Example
$ curl -O www.tutorialspoint.com/index.htm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left
Speed
100 81285 0 81285 0 0 49794 0 --:--:-- 0:00:01 --:--:--
60077
It creates a new file with the name index.htm and saves the source code of the index page
of tutorialspoint.com in it.
Hello CouchDB
You can access the homepage of the CouchDB by sending a GET request to the CouchDB
instance installed. First of all make sure you have installed CouchDB in your Linux
environment and it is running successfully, and then use the following syntax to send a get
request to the CouchDB instance.
curl http://127.0.0.1:5984/
This gives you a JSON document as shown below where CouchDB specifies the details such
as version number, name of the vendor, and version of the software.
$ curl http://127.0.0.1:5984/
{
"couchdb" : "Welcome",
"uuid" : "8f0d59acd0e179f5e9f0075fa1f5e804",
"version" : "1.6.1",
"vendor" : {
"name":"The Apache Software Foundation",
"version":"1.6.1"
}
}
Creating a Database
You can create a database in CouchDB using cURL with PUT header using the following
syntax −
Example
As an example, using the above given syntax create a database with name my_database
as shown below.
Verification
Verify whether the database is created, by listing out all the databases as shown below. Here
you can observe the name of newly created database, "my_database" in the list
Example
As an example let us get the information of the database named my_database as shown
below. Here you can get the information about your database as a response.
{
"db_name" : "my_database",
"doc_count" : 0,
"doc_del_count" : 0,
"update_seq" : 0,
"purge_seq" : 0,
"compact_running" : false,
"disk_size" : 79,
"data_size" : 0,
"instance_start_time" : "1423628520835029",
"disk_format_version" : 6,
"committed_update_seq" : 0
}
Futon
Futon is the built-in, web based, administration interface of CouchDB. It provides a simple
graphical interface using which you can interact with CouchDB. It is a naive interface and it
provides full access to all CouchDB features. Following is the list of those features −
Databases −
Creates databases.
Destroys databases.
Documents −
Creates documents.
Updates documents.
Edits documents.
Deletes documents.
Starting Futon
Make sure CouchDB is running and then open the following url in browser −
http://127.0.0.1:5984/_utils/
If you open this url, it displays the Futon home page as shown below −
On the left hand side of this page you can observe the list of all the current
databases of CouchDB. In this illustration, we have a database named
my_database, along with system defined databases _replicator and _user.
Recent Databases − Under this you can find the names of recently added
databases.