by Jeff Eaton

Module Monday: Views Datasource

Building web services and exposing APIs to access your site's content is the new hotness of site building. The work of actually building the custom information feeds that drive those cool features can be daunting, however. Enter the Views Datasource module: it allows you to output content lists built with the Views module in a wide variety of standard web formats.

Screenshot of administration screen

Setting up Views Datasource is straightforward; create a normal field-based view, then set up a Page display for it and choose one of the Views Datasource output styles. It can create feeds in RDF, XML, and JSON formats and supports a number of common variants of those types like FOAF, OPML, SIOC, hCard, hCalendar, and more. Once you've chosen an output style, you can tweak a variety of settings exclusive to the format: escaping policies for rich text, header and footer data, and so on.

XML. Isn't it pretty?

One slick trick the module supports is automatic output of date-oriented content in the format used by MIT's SIMILE Javascript library. Create a view using Views Datasource, point the SIMILE Timeline library at it, and you've got an instant browse-able timeline that can be easily embedded elsewhere on the web. The other output formats it supports can be consumed and repurposed in similar ways by various Javascript libraries and third-party applications.

Image of a timeline created with MIT's SIMILE library and JSON data

Views Datasource may not be as flexible as generating your own API feeds with custom code, but because it's built on the Views module it makes putting together simple data feeds ridiculously easy. That simplicity and flexibility makes it a great compliment to the Services module, which handles reading and writing individual content elements via standard web APIs. At the time of this writing it's available for Drupal 5 and 6, and a Drupal 7 port is underway. Check it out!