Using REST to enumerate CouchDB records

REST semantics dictate that to fetch the full contents of a collection of objects, we just send a GET request to the collection's root. We can do that from a web client to a CouchDB with CORS enabled using jQuery with a single call.

How to do it...

Here's some HTML, jQuery, and JavaScript that enumerate all items in a CouchDB view and shows some of the fields of each objects in an embedded table:

<!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> </head> <body> <p>Hello world</p> <p> <div id="debug"></div> </p> <p> <div id="json"></div> </p> <p> <div id="result"></div> </p> <button type="button" id="get" ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.