# 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/103017>\
**Category:** Ruby\
**Created:** [April 30, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/103017 "2007-04-30T21:30:26Z")\
**Posts on this page:** 4\
**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, 9:30pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/103017/1 "2007-04-30T21:30:26Z")

</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:** [April 30, 2007, 10:18pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/103017/2 "2007-04-30T22:18:51Z")

</div>

On Tue, May 01, 2007 at 04:30:05AM +0900, dt wrote:

> I like SOA, I like Ajax, I like Ruby/Rails, but I am in doubt how to  
> make some things.

You’ll get better answers from the RoR google group. You’ve come to the  
Ruby  
Language mailing list.

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

Buy a copy of “Agile Web D. with Rails” (as PDF or full paper  
book). Chapter 25 is all about web services on Rails.

> - How should I be able to make a service in Rails that uses HTTP GET  
> instead of SOAP or XML methods?

Perhaps you want to consider RESTful routing instead of web services.

GET /things – returns a list of things (as HTML)  
GET /things.xml – returns a list of things (as XML)  
GET /things/1 – returns thing number 1  
GET /things/1.xml

Brian.

---

<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, 10:32pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/103017/3 "2007-04-30T22:32:53Z")

</div>

On 4/30/07, dt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

Are you talking about just using URL-encoded query strings instead of  
formats that are more elaborate but possibly more portable? If so, why?

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

In the apps I’ve been writing lately, I’ve been making the server-side  
generate nothing but very generalized XML. To convert it to JSON,  
procedural  
JS code, XUL, XHTML, or even other XML representations, I’ve been using  
XSLT  
_on the client._ Seems ugly but it turns out not to be as bad as it  
sounds.  
And it certainly beats the alternative, which is to build server logic  
with  
a particular presentation model in mind. And it also fits the canonical  
goal  
of doing the work closest to where it will be used.

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

Again, speaking of my recent work, I’ve avoided Rails on the backend  
because  
my HTTP servers now look a lot like generic service providers, rather  
than  
“controllers” and “views” that integrate data with presentation logic.  
(They  
also need very high performance, they must interface through messaging  
with  
other backend service providers, and they can’t block while processing  
any  
given request, so Rails is a poor fit anyway.)

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).

Having gotten into XUL rather heavily lately, I have to say it’s a very  
fine  
approach but nets out as a near miss. The Gecko platform isn’t quite  
stable  
enough for prime time, and the tooling is very immature. For something  
that’s been around for quite a few years now, I expected more. I have a  
colleague that’s totally sold on Flex, though, and I’m planning to learn  
it  
next, especially now that Adobe is planning to open-source more of it.

---

<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:25pm UTC](https://www.ruby-forum.com/t/rails-web-services-in-general-http-get-and-json-and-other/103017/4 "2007-04-30T23:25:57Z")

</div>

Brian, thanks for a reply.

> You’ll get better answers from the RoR google group. You’ve come to the Ruby  
> Language mailing list.  
> Sorry, my mistake. Will post to RoR group.

> Buy a copy of “Agile Web D. with Rails” (as PDF or full paper  
> book). Chapter 25 is all about web services on Rails.  
> Thanks for a recommendation. Will look at this if I have time.

> Perhaps you want to consider RESTful routing instead of web services.
> 
> GET /things – returns a list of things (as HTML)  
> GET /things.xml – returns a list of things (as XML)  
> GET /things/1 – returns thing number 1  
> GET /things/1.xml
> 
> Brian.  
> Will do this too. Thanks again!
