CouchDB is a document database. It stores JSON objects with a few special field names. The _id field represents a unique identifier for a document. The _rev field is the revision marker for a document. The _rev field is used for Multi-Version Concurrency Control, a form of optimistic concurrency.
5. http-console
$ npm install http-console -g
$ http-console 127.0.0.1:5984
> http-console 0.6.3
> Welcome, enter .help if you're lost.
> Connecting to 127.0.0.1 on port 5984.
@BradleyHolthttps://github.com/cloudhead/http-console
6. Connecting to CouchDB 2.0
$ http-console root:passw0rd@127.0.0.1:5984 --json
@BradleyHolt
7. Connecting to CouchDB 2.0
$ http-console root:passw0rd@127.0.0.1:5984 --json
> http-console 0.6.3
> Welcome, enter .help if you're lost.
> Connecting to 127.0.0.1 on port 5984.
@BradleyHolt
8. Connecting to IBM Cloudant
$ http-console https://bradley-holt:passw0rd@bradley-holt.cloudant.com --json
@BradleyHolt
9. Connecting to IBM Cloudant
$ http-console https://bradley-holt:passw0rd@bradley-holt.cloudant.com --json
> http-console 0.6.3
> Welcome, enter .help if you're lost.
> Connecting to bradley-holt.cloudant.com on port 443.
@BradleyHolt
13. PUT a Database
/> PUT /kittens
...
HTTP/1.1 201 Created
Content-Type: application/json
Location: http://127.0.0.1/kittens
{ ok: true }
@BradleyHolt
34. PUT an Attachment
/kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a
... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=
@BradleyHolt
35. PUT an Attachment
/kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a
... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=
HTTP/1.1 201 Created
Content-Type: application/json
Location: http://127.0.0.1/kittens/mittens/photo
{
ok: true,
id: 'mittens',
rev: '2-d858e51453a5785bafe517b7eddc5a98'
}
@BradleyHolt
36. PUT an Attachment
/kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a
... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=
HTTP/1.1 201 Created
Content-Type: application/json
Location: http://127.0.0.1/kittens/mittens/photo
{
ok: true,
id: 'mittens',
rev: '2-d858e51453a5785bafe517b7eddc5a98'
}
/kittens>
@BradleyHolt
37. PUT an Attachment
/kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a
... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=
HTTP/1.1 201 Created
Content-Type: application/json
Location: http://127.0.0.1/kittens/mittens/photo
{
ok: true,
id: 'mittens',
rev: '2-d858e51453a5785bafe517b7eddc5a98'
}
/kittens> Content-Type: application/json
@BradleyHolt
40. GET an Attachment
/kittens> GET /mittens/photo
HTTP/1.1 200 OK
Content-Type: image/gif
Etag: "UsqjdPnY6ApD2ENFOglFHg=="
R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=
@BradleyHolt
63. Delete the Database
/> DELETE /kittens
HTTP/1.1 200 OK
Content-Type: application/json
{ ok: true }
@BradleyHolt
64. Try It On Your Own
1. Create a database
2. Create a document in the database
3. Read the document
4. Update the document
5. Delete the document
6. Delete the database
@BradleyHolt
CouchDB is a document database
JSON objects with a few special field names
_id field represents unique identifier for a document
_rev field is the revision marker for a document
_rev field is used for Multi-Version Concurrency Control, a form of optimistic concurrency
HTTP Basic authentication is a simple way to authenticate with an HTTP server
Other approaches, such as cookies and OAuth, are often used as well
Resources can be represented in different content types