O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Web Services

Although this book started out by examining how to use Rails to generate HTML, you can create Rails applications that are meant to be used by other programs as web services. The RESTful scaffolding already provides a foundation, if those other programs can work with a RESTful approach. However, some environments demand SOAP (or the much simpler, older, XML-RPC). For those situations, you’ll want to use the ActionWebService plug-in, or a newer version that was released as the datanoise-actionwebservice gem (http://www.datanoise.com/articles/2008/7/2/actionwebservice-is-back).

ActionWebService provides a generator and framework that works much like the rest of Rails, except that it works with the SOAP, WSDL (Web Services Description Language), and XML-RPC protocols. Compared to a RESTful application, these have simpler routing to a given URL, but more complicated interior processing, which ActionWebServices handles through an additional layer of dispatching.

If your Rails application needs to consume SOAP services, you can use Ruby’s built-in Soap4r library and the built-in XMLRPC library for XML-RPC services. For more information, see Web Services on Rails (O’Reilly, 2006).

To reliably generate custom XML for consumption by other programs in a more precise way than to_xml or render :xml permit, you’ll want to explore Builder view templates.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required