Maybe if I explain myself a bit better, I 'll get some more feedback
I’ve been thinking a lot about what a restful interface should look
like and I’ve been primarily looking at Rails’ implementation. As I’ve
been thinking about it, and looking at Roy Fielding’s talk on the
subject, I think that there is something missing with the XML
serialization in rails. This is based on my observations of how Rails
seems to be creating its XML representations.
The issue concerns associated objects; the has_many and belongs_to
crowd. According to my understanding of Roy’s presentation (I’ll read
his dissertation, I promise), a representation of a resource exposes
its associated resources through its URL.
Let me give an example. Lets say I have the following models:
class Blog < ActiveRecord::Base
class Author < ActiveRecord::Base
Assuming that these are both resources, you’ll get something like:
From Roy’s presentation I think that the “REST Way” to do things would
be more like:
I might also put the URI in an element but this way seems a lot more
compact. Besides, the URI is really metadata in this sense.
I think that this approach has a number of advantages. First is
polymorphism. Not that it wouldn’t be challenging for your framework
to handle but the following member representation seems very
compelling (I’m going to skip the type attributes as I think they’re
tedious for examples):
I’ve represented a polymorphic association without having to express
what types the members are. I can determine that when I retrieve the
The second advantage is crossing the domain boundary. I was thinking
that it might be nice to refer to members by their Open ID uri but I
suspect that might not be a good example. However, we might extend or
previous example a bit:
Depending on what is consuming your API that may or may not be
problematic. I wouldn’t see a problem with this if I was building a
associate an ActiveResource with an XML Schema rather than a URL, this
would be feasible in Rails.
Since not all associated objects are made into resources (for instance
join objects for has_many :through), those associations should be
realized directly in the XML representation (I believe the :include
option does this now).
So back to my questions. I want to be able to do all this without
having to create view files for each model I create. Instead I want to
create a plugin that modifies how to_xml works to give me the
behaviour I want. The only problem is that I’m having a hard time
getting my head around which methods of which classes I need to
override to get all this to happen.