The document describes the basic CRUD (Create, Read, Update, Delete) operations for CouchDB databases and documents. It provides the syntax and examples for creating and deleting databases, creating, reading, updating, and deleting documents, and attaching files to documents. The operations make use of cURL commands to interface with CouchDB through HTTP at the given port (5984 in examples). Verification steps using cURL are included to check the results of each operation.
1 of 2
Download to read offline
More Related Content
Quick reference for curl
1. CREATING A DATABASE
======== = ========
Syntax
curl -X PUT http://127.0.0.1:5984/database_name
Ex
curl -X PUT http://127.0.0.1:5984/my_database
Verification
curl -X GET http://127.0.0.1:5984/_all_dbs
--------------------------------------------------------------------------------
-----------------------------------------------------
DELETING A DATABASE
======== = ========
Syntax
curl -X DELETE http://127.0.0.1:5984/database_name
Ex
curl -X DELETE http://127.0.0.1:5984/my_database2
Verification
curl -X GET http://127.0.0.1:5984/_all_dbs
--------------------------------------------------------------------------------
-----------------------------------------------------
CREATING A DOCUMENT
======== = ========
Syntax
curl -X PUT http://127.0.0.1:5984/database name/"id" -d ' { document} '
Ex
curl -X PUT http://127.0.0.1:5984/my_database/"001" -d '{ " Name " : " Raju " ,
" age " :" 23 " , " Designation " : " Designer " }'
Verification
curl -X GET http://127.0.0.1:5984/my_database/001
--------------------------------------------------------------------------------
-----------------------------------------------------
UPDATING A DOCUMENT
======== = ========
curl -X PUT http://127.0.0.1:5984/database_name/document_id/ -d '{ "field" :
"value", "_rev" : "revision id" }'
Verification
curl -X GET http://127.0.0.1:5984/my_database/001
Ex
curl -X PUT http://127.0.0.1:5984/my_database/001/ -d ' { " age " : " 24 " , "
_rev " : " 1-1c2fae390fa5475d9b809301bbf3f25e " } ' { " ok " : true , " id " : "
001 " , " rev " : " 2-04d8eac1680d237ca25b68b36b8899d3 " }
Verification
curl -X GET http://127.0.0.1:5984/my_database/001
--------------------------------------------------------------------------------
-----------------------------------------------------
DELETING A DOCUMENT
======== = ========
Syntax
curl -X DELETE http://127.0.0.1:5984/database_name/database_id?_rev
Verification
curl -X GET http://127.0.0.1:5984/my_database/001
Ex
curl -X DELETE http://127.0.0.1:5984/my_database/001?rev=1-
3fcc78daac7a90803f0a5e383f4f1e1e
Verification
curl -X GET http://127.0.0.1:5984/my_database/001
--------------------------------------------------------------------------------
-----------------------------------------------------
ATTACHING FILES
========= =====
Syntax
curl -vX PUT http://127.0.0.1:5984/database_name/database_id/filename?
rev=document rev_id --data-binary @filename -H "Content-Type:type of the
content"
2. Verification
curl -X GET http://127.0.0.1:5984/my_database/001
Ex
curl -vX PUT http://127.0.0.1:5984/my_database/001/boy.jpg?rev=1-
967a00dff5e02add41819138abb3284d --data-binary @boy.jpg -H
"ContentType:image/jpg"
Verification
curl -X GET http://127.0.0.1:5984/my_database/001