Accessing the CouchDB changes stream with Cradle
One of CouchDB's most noteworthy features is the _changes
API. With it, we can view all the alterations to a database via HTTP.
For instance, to see all the changes made to our quotes
database, we can make a GET request to http://localhost:5984/quotes/_changes
. Even better, if we want to hook up to a live stream, we need to add the query parameter ?feed=continuous
.
Cradle provides an attractive interface to the _changes
API, which we'll explore in this recipe.
Getting ready
We'll need a functioning CouchDB database and a way to write to it. We can use the quotes.js
example used in Storing data to CouchDB with Cradle, so let's copy that into a new directory and then create a file alongside it named quotes_stream.js
.
If we followed the Creating an admin user and Locking all modifying operations to an admin user sections of the previous recipe's There's moreā¦ section, we will need to modify the second line of quotes.js
in order to continue to insert...