Douglass Turner
2005-Oct-13 15:18 UTC
REST Style Web Service in Rails - Looking for example
Hello, Can anyone point me to an example of a REST style web service implemented in Rails? Yes, I have looked at Action Web Service but that is SOAP/WSDL style which is a bit overkill for my needs. Thanks, Doug Turner
John Wilger
2005-Oct-14 18:29 UTC
Re: REST Style Web Service in Rails - Looking for example
On 10/13/05, Douglass Turner <douglass.turner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > Can anyone point me to an example of a REST style web service > implemented in Rails? Yes, I have looked at Action Web Service but > that is SOAP/WSDL style which is a bit overkill for my needs.A REST API is exactly what your web browser uses when you browse websites. There''s really nothing special about it. You can think of the URL as the function call (with any query-string being the arguments), and the body of the response is the return value. So if you were trying to communicate between two machines, you might just use a template that returns an XML document or some other format that the client knows how to interpret. As a simple example, lets say you want to call "http://www.example.com/math/add_one?input=1". You might have this for a controller: class MathController < ApplicationController def add_one @result = params[ :input ].to_i + 1 end end And you might have a template ''app/views/math/add_one.rhtml'': <%= @result %> Alternatively (and prefferably in this simple example) you could skip the template file altogether: class MathController < ApplicationController def add_one render :text => ( params[ :input ].to_i + 1 ).to_s end end -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland