RESTless Ruby?

Hi all,

I'm aware of xml-rpc and soap implementations for Ruby. Does anyone
have a REST implementation for Ruby?

A few links:

http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
http://www.tbray.org/ongoing/When/200x/2003/05/12/SoapAgain
http://radio.weblogs.com/0101679/stories/2002/07/20/restSoap.html
http://www.xml.com/pub/a/2002/05/08/deviant.html

I've seen a few discussions, but no actual implementation - or is
there no such thing really, since it's HTTP?

I can read all the papers in the world, but I live by examples! :slight_smile:

Regards,

Dan

djberg96@hotmail.com (Daniel Berger) writes:

I've seen a few discussions, but no actual implementation - or is
there no such thing really, since it's HTTP?

Most REST over HTTP implementation is really thin to almost
non-existent as REST is mostly a discipline in URI creation and
access, rather than protocol specification like in xml-rpc and soap.

There is no specification on data format exchanged between the client
and server. Some would use HTML, some plain text, but the most common
one is XML with custom schema.

I can read all the papers in the world, but I live by examples! :slight_smile:

Following is some example of REST-ful URI:

GET /document?id=3 #=> get document #3
POST /document (posted data: id=3&author='another person') #=> update document #3
PUT /document (document data putted) #=> insert new document

Some hints:

1. Move session handling or state-related info outside of the REST
   server, i.e. ideally it should be stateless.

2. If you can't move it outside of the REST server, make it a
   first-order resource: /session or /state.

3. Try to use only nouns to name the resources: /view_document
   contains verb, /document would be better. The verb is implied from
   the HTTP request method you use, e.g.: GET -> view, POST -> update,
   PUT -> insert.

Regarding REST implementation in Ruby, any decent HTTP server would
do; WEBrick is one of them.

YS.

Daniel Berger wrote:

Hi all,

I'm aware of xml-rpc and soap implementations for Ruby. Does anyone
have a REST implementation for Ruby?

A few links:

Architectural Styles and the Design of Network-based Software Architectures
ongoing by Tim Bray · The SOAP/XML-RPC/REST Saga, Chap. 51
http://radio.weblogs.com/0101679/stories/2002/07/20/restSoap.html
REST Roundup

I've seen a few discussions, but no actual implementation - or is
there no such thing really, since it's HTTP?

REST typically comes up in discussions of Web services, and SOA in
general. But there is no canonical implementation per se.

I can read all the papers in the world, but I live by examples! :slight_smile:

I found this page to be helpful in explaining this with an example:

  http://www.xfront.com/REST-Web-Services.html

James

Rest by example:

http://rest.blueoxen.net/cgi-bin/wiki.pl?ErikTerpstra

Daniel Berger wrote:

···

Hi all,

I'm aware of xml-rpc and soap implementations for Ruby. Does anyone
have a REST implementation for Ruby?

A few links:

Architectural Styles and the Design of Network-based Software Architectures
ongoing by Tim Bray · The SOAP/XML-RPC/REST Saga, Chap. 51
http://radio.weblogs.com/0101679/stories/2002/07/20/restSoap.html
REST Roundup

I've seen a few discussions, but no actual implementation - or is
there no such thing really, since it's HTTP?

I can read all the papers in the world, but I live by examples! :slight_smile:

Regards,

Dan

I found this page to be helpful in explaining this with an example:
  http://www.xfront.com/REST-Web-Services.html

That puts into words many techniques we've been using intuitively for years now.
(even before the "web services" term was coined)

Apart from that, I've also found it interesting to provide some
metadata about the service itself, this resembles more to command
line help than WSDL, being it lightweight, it can be used for both human
and computer consumption when called without parameters.

Say for example
/////////////
request: GET http://restserver/temperature?format=xml
response:
<?xml version="1.0" ?>
<service name="temperature">
        <input>
               <parameter name="system" type="string" optional="yes"
default="fahrenheit">
               <parameter name="convert_to" type="string"
optional="yes" default="celcius">
               <parameter name="degrees" type="float" optional="no">
        </input>
        <output>
                <parameter type="float" name="result">
        </output>
</service>
/////////////
request: GET http://restserver/temperature?format=ascii
usage: /temperature [system="fahrenheit"] [convert_to="celcius"] degrees=Float
returns: Float result
//////////////

I sometimes provide something like:
request: GET http://restserver/services
response:
<?xml version="1.0" ?>
       <service_list>
          <service name="temperature" />
          <service name="random" />
          <service name="customer_record" />
       </service_list>

/////////////

This can be useful to automate your services tests

hope this helps,

--- vruz