rendered paste body$ curl -X GET localhost:5984/
{"couchdb":"Welcome","version":"1.0.2"}
$
$ # Ce DB-uri avem?
$ curl -X GET localhost:5984/_all_dbs
["_users","newdb"]
$
$ # newdb am facut-o eu
$ curl -X GET localhost:5984/newdb
{"db_name":"newdb","doc_count":2,"doc_del_count":0,"update_seq":2,"purge_seq":0,"compact_running":false,"disk_size":8281,"instance_start_time":"1304860740497214","disk_format_version":5,"committed_update_seq":2}
$
$ # hai sa general niste numere random pentru ID-uri
$ curl -X GET localhost:5984/_uuids
{"uuids":["1167cf62f1b09db1e94a8b156a002eac"]}
$ curl -X GET localhost:5984/_uuids
{"uuids":["1167cf62f1b09db1e94a8b156a0036e2"]}
$
$ # adaugam un nou document
$ curl -X PUT localhost:5984/newdb/1167cf62f1b09db1e94a8b156a002eac -d '{"title":"Andreea", "description":"cea mai faina"}'
{"ok":true,"id":"1167cf62f1b09db1e94a8b156a002eac","rev":"1-1659f0917f05bfb55a0f452a978f37e2"}
$
$ # verificam documentul
$ curl -X GET localhost:5984/newdb/1167cf62f1b09db1e94a8b156a002eac
{"_id":"1167cf62f1b09db1e94a8b156a002eac","_rev":"1-1659f0917f05bfb55a0f452a978f37e2","title":"Andreea","description":"cea mai faina"}
$
$ # hai sa facem acuma si din python
$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>>
>>> conn = httplib.HTTPConnection("localhost", 5984)
>>>
>>> # O cautam intai pe andreea
>>> conn.request("GET", "/newdb/1167cf62f1b09db1e94a8b156a002eac");
>>> resp = conn.getresponse()
>>> print resp.read()
{"_id":"1167cf62f1b09db1e94a8b156a002eac","_rev":"1-1659f0917f05bfb55a0f452a978f37e2","title":"Andreea","description":"cea mai faina"}
>>> # sa incercam sa adaugam ceva
...
>>> conn.request("PUT", "/newdb/1167cf62f1b09db1e94a8b156a0046bf", '{"title":"Aram", "description":"zam zam"}')
>>> resp = conn.getresponse()
>>> print resp.status, resp.read()
201 {"ok":true,"id":"1167cf62f1b09db1e94a8b156a0046bf","rev":"1-24b30fa351595e11121312ff1b8a57b0"}
>>> # verificam daca a mers
...
>>> conn = httplib.HTTPConnection("localhost", 5984)
>>> conn.request("GET", "/newdb/1167cf62f1b09db1e94a8b156a0046bf");
>>> resp = conn.getresponse()
>>> print resp.status, resp.read()
200 {"_id":"1167cf62f1b09db1e94a8b156a0046bf","_rev":"1-24b30fa351595e11121312ff1b8a57b0","title":"Aram","description":"zam zam"}