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

**URL:** <https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/105477>\
**Category:** Rails\
**Created:** [April 30, 2007, 11:26pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/105477 "2007-04-30T23:26:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtdtdt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dtdtdt](https://www.ruby-forum.com/u/dtdtdt)\
**Post date:** [April 30, 2007, 11:26pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/105477/1 "2007-04-30T23:26:57Z")

</div>

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](http://manuals.rubyonrails.com/read/book/10)), 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.

---

<div class="post-metadata">

**Author:** ![dtdtdt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dtdtdt](https://www.ruby-forum.com/u/dtdtdt)\
**Post date:** [May 1, 2007, 8:15am UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/105477/2 "2007-05-01T08:15:31Z")

</div>

> - 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](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.
