Who are we?

We are a group of enthousiastic people working for Nedap, a Dutch company with a single goal: solve problems.

« Cha-Ching and dutch banks | Main | Solving PO translation conflicts »

ActiveResource: REST, WSDL, XSD?

We love REST. It's simple and clean, and combined with ActiveResource it is certainly the best app to app bridge we've worked with so far. But...

What if you want to have more freedom? Say we want to build a database based on a REST webservice. Now imagine we don't want any info about the service in the ruby program that actually builds the db.

We are facing two major problems:

  • We don't know which resources are available.
  • We don't know the fields and types of the resource in advance.

The first problem will eventually be solved with WSDL 2.0 or if you need a solution right now: by a default listing resource.

 # Our default object is called a Resource, on the server we have 
 # a Resource object that just returns each resource we have in 
 # a string array.
 resources = Resource.find(:all)
   => ["address","person","country"]

 # Now we can do all kinds of crazy stuff :)
 resources.each do |resource|
   name = resource.capitalize.to_sym
   new_resource = Object.const_set(name, Class.new(ActiveResource::Base))
   new_resource.site = Resource.site

After this little piece of code we have a full dynamic set of ActiveResource classes ready to be used :)

The second problem we face is much more interesting. Normally some kind of resource definition would be applied like XSD. But native ruby XSD support is kind of lacking (it sucks) and more importantly it doesn't feel like a rails solution.

We wanted a cleaner, simpler and more elegant (more RESTy) solution. How about Person.schema?

It returns an ActiveResourceSchema object:

   => { :name => FixNum, :date_of_birth => DateTime, 
:parents => [{ :id => FixNum }] }

What happens is actually quite simple. When the Resource objects receives the schema method call it calls:

find(:first, :params => { :schema => true }).

The server responds to this param with a sample record, with just the field names and types. We build an ActiveResourceSchema object to wrap those and return a nice array of fields :)

Note: These code snippets are just examples, we are currently building this. If there's enough interest we might submit it as a plugin/patch for ARes.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (7)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: useful reference
    Nice Webpage, Maintain the fantastic job. Thanks!
  • Response
    Response: fishing equipments
    Moves on Rails - Journal - ActiveResource: REST, WSDL,
  • Response
    Response: kayak fish finder
    Moves on Rails - Journal - ActiveResource: REST, WSDL,
  • Response
    Moves on Rails - Journal - ActiveResource: REST, WSDL,
  • Response
    Moves on Rails - Journal - ActiveResource: REST, WSDL,
  • Response
    Response: best fish finder
    Moves on Rails - Journal - ActiveResource: REST, WSDL,
  • Response
    Moves on Rails - Journal - ActiveResource: REST, WSDL,

Reader Comments (4)

A short time ago, the exact most stunning actress all over the world Angelina Jolie was spotted wearing a nice seeking replica watches on not a couple of occasions. And I've been very curious about what precisely the exact watch is. And these days my great friend Mike who functions for replica michael kors watches a fashion magazine pointed out the exact secret for me. I personal a thank to him.

August 9, 2010 | Unregistered Commenterwatch.watcheslux

very creative! I like it very much,but If you can add more video and pictures can be much better, I have never read such a lovely article and I am coming back tomorrow to continue reading.omega constellation

November 23, 2010 | Unregistered CommenterHimbags D. Craig

footwear you need the most. You can Nike Air Jordans Shoes find a better selection of shoes and sandal online that fits your UGG Classic Tall Boots 5812 style as well as your budget.
Through the years,

Your website have very interesting article. I got knowledge from here. Besides that, your blog is so popular among the searchers from search engines. It means yours website is very goodAlarm Monitoring Houston [url=http://www.smithmonitoring.com/houston-security/]Alarm Monitoring Houston[/url]

December 2, 2011 | Unregistered CommenterAlarm Monitoring Houston

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>