I propose that Rails and ActiveResource add support for retrieving a
model's schema via REST.  This could make it much easier for REST
clients to auto-figure out attributes, the way that ActiveRecord uses
the database to do the same thing.

The best location for this is, I think, at "/users/new.xml", using a
"User" model as the example.  The HTML at "/users/new" provides the
form needed to create a new instance, and the XML version would
provide the information needed to do the same thing remotely.

Here's one idea for a clean syntax for doing this (also at
http://pastie.caboo.se/55138):

respond_to do |format|
  format.xml { render :xml => User.to_xml }
end

This would mean writing a to_xml function on ActiveRecord::Base as a
class method.  The XML this produces could look like the normal AR
to_xml format, just without any content.  An example:

http://pastie.caboo.se/55136

I've been working on an ActiveResource client in JavaScript, and it's
impossible to just assign properties to an object and for the object
to know that these are attributes to be submitted along with any POST
or PUT call.  ActiveResource has a partial solution to this by taking
advantage of Ruby's method_missing, so any unknown properties that get
assigned can be caught and recognized as formal attributes.  Clients
written in strongly typed languages would have an even harder time
than JavaScript.  Including an easy way to advertise the schema would
ease the burden of any REST client.

More generally, I think this makes the Rails REST standard more
complete, by affording an ActiveResource client the same level of
schema knowledge that an ActiveRecord server has.

What do you guys think?  Would this be a useful extension to the
current REST standard Rails is advocating?  I think the most
interesting part of this is the XML format, and I'd really like to
form something the community agrees with as I construct a patch for
this.

-- Eric Mill


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to