MoviesWebService

In our web service we will create an interface that is very similar to the back-end service interface we created in previous chapters. In part, this is to show that mechanisms for passing messages back and forth are largely interchangeable, and also to show that a RESTful interface does not need to represent a total paradigm shift if you don’t want it to.

In fact, if we wanted to provide a RESTful interface in addition to our XML-RPC interface in our back-end service, we could do so using the same ActionWebService::Struct classes. Example 18-7 shows our Movie class from the XML-RPC service, now marked up with ROXML. Using the techniques in the rest of this chapter, we could have provided an identical interface as our XML-RPC API, using RESTful techniques. In fact, it’s even possible that the RESTful interface could be generated from the same style of API definition as the XML-RPC API files. Of course, this is not currently supported, but it is a possible future direction and would certainly ease transition to REST, should your organization wish to do so.

Example 18-7. An ActionWebService class annotated with ROXML

module Logical
  class Movie < ActionWebService::Struct
    include ROXML

    xml_attribute :id
    xml_text :name
    xml_text :rating_id
    xml_text :rating_description
    xml_text :length_minutes

    member :id,                    :integer
    member :name,                  :string
    member :length_minutes,        :integer
    member :rating_id,             :string
    member :rating_description,    :string
  end
end

Resources Server Implementation

In

Get Enterprise 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.