9.6. Summary

ActiveResource is the Rails 2.0 solution to acting as a web service and consuming other web services. If you have created a RESTful interface to your application, then you have a web service API more or less for free.

ActiveResource is the web-client equivalent of ActiveRecord, allowing you to find, update, create, and delete resources on a remote server, given the base URL and a REST interface. Although it's not as fully functional as ActiveRecord, ActiveResource remains a useful way to deal with remote objects that you can access via HTTP.

Rails provides to_xml methods for most classes, such as ActiveRecord::Base, to enable creation of web service data. Rails also provides XML builder templates for even more customization of the XML output from your controllers.

To produce feed data, you can use the Atom Feed helper to produce Atom feeds, or the Ruby RSS library to create RSS feeds. Rails also provides mechanisms to output JSON and YAML.

To parse XML data, Ruby Standard Library's REXML toolkit is recommended. It converts XML files to Ruby objects, and can be used to parse RSS and Atom feeds.

Get Professional Ruby on Rails™ 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.