Rails Web services (in general), HTTP GET and JSON and other

Hi,

I like SOA, I like Ajax, I like Ruby/Rails, but I am in doubt how to
make some things. There are always solutions, but my idea is not
solving the problem, but learning the best way to solve it. I didn’t
find nearly enough information about what I’ve been thinking to do.
Here are some of the questions I would like to find the answer to:

  • Does anybody know a good tutorial about Rails Web services? I have
    searched the Net, but I couldn’t find anything else then a simple
    examples (e.g. Peak Obsession), which do
    not answer many of my questions.

  • How should I be able to make a service in Rails that uses HTTP GET
    instead of SOAP or XML methods? I would like both input and output to
    be configured not to adhere to SOAP protocol or to use XML. I could
    use query_parameters, however that would be ugly - native SOAP or
    plain XML calls to Web services are directly translating the
    parameters to the parameters in the method declaration.

  • While we are here, how/where are the parameters from SOAP or plain
    XML request translated into the method parameters? Any good text about
    this? This might give me some idea on how to approach this. For
    example, how could one make a protocol, logically similar to SOAP, and
    implement a Web service whose methods would get the parameters from
    the request in the same fashion they do it with SOAP.

  • How can I use JSON with a Rails Web service? I would like to make
    some Ajax calls, however I wouldn’t like to parse XML since JSON is
    much more natural JavaScript thing then parsing XML. I tried using
    render :json, but no success until now. JSON is much easier to work
    with in JavaScript then XML, so this seems like a nice feature if it’s
    possible.

  • Is there some non-trivial example of Rails Web services used
    dynamically (Ajax), especially not directly from a HTML page, but from
    e.g. XUL or Flex application? This is important because, as far as I
    understand, Rails is not made to directly support building such
    applications.

I assume this is interesting to other people, too. If not, let me know
if this is the right approach - maybe there are much easier/better
ways. The problem that needs to be solved is making a simple client-
side application which uses Rails Web services to fetch the data (and
other things - e.g. authentication). I am not constrained to anything
on the client, but I suppose I will be doing it in XUL or similar
(Flex maybe). I would use JavaScript for remotely calling (Ajax) the
necessary Web services. They would return data only and as much
processing as possible should be done on the client side (it’s not
much of a processing anyway).

Any thoughts on this? I would like to make this a general discussion
about how applications should be built. I would like to use Ruby/Rails
on the server, since I consider it very succinct comparing it to e.g.
Java for many of the tasks necessary. I am new to this (as many of the
people here) and I consider the documentation about this topic to be
scarce.

I would ask anyone posting to also say their opinion on the above
questions - am I just working on something I shouldn’t be? Are there
better ways? Why is this way a bad one (or a good one)? Maybe the most
important thing - if you could, provide some links to the sites where
information could be found about these or even better links to the
running sites which provide a proof-of-concept.

  • Is there some non-trivial example of Rails Web services used
    dynamically (Ajax), especially not directly from a HTML page, but from
    e.g. XUL or Flex application? This is important because, as far as I
    understand, Rails is not made to directly support building such
    applications.

Yes.

Shameless plug: you can download the MIT-licensed code samples from my
Flexible Rails book from http://www.flexiblerails.com/code-samples.
Unzip the file and look in the iteration22 folder for the most fully
developed example. It shows a Flex 2 application built using
Cairngorm talking to Rails via HTTPService.

(The application is developed iteratively, and is explained in great
detail in the book. However, since the code is MIT-licensed, you can
use it regardless of whether you buy the book.)

Cheers,
Peter A.