Rails Nested Resource Issues
David Lutterkort
lutter at redhat.com
Thu Sep 20 19:50:27 UTC 2012
On Thu, 2012-09-20 at 13:20 +0100, Martyn Taylor wrote:
> Gents.
>
> I'm having some trouble with getting nested resources working properly
> from bespoke XML/JSON in RESTful API. There seems to be some
> fundamental problems with the way rails works, which means we have to
> write a lot of bespoke code to get it working, possibly even having to
> monkey patch Rails itself.
>
> I've written an example rails app that highlights the problem and put a
> detailed description in the README you can find it here:
>
> https://github.com/mtaylor/Rails-Nested-Resource-Issues
>
> I've ran into this issue on IME. But it's going to affect us across all
> rails projects with REST APIs, so we could do with discussing this issue
> and coming up with the best possible solution that results in as little
> replication as possible.
>
> Please read through the problem and let me know if you have any better
> ideas that the solutions I have proposed.
The sample app does a nice job of explaining the problem - my issue with
Rails' REST support though has always been that the XML/JSON
representation is essentially a dump of the DB schema, meaning the XML
changes when the DB schema changes. Not good for a stable API.
For Deltacloud (where we use Sinatra, not Rails), we have a similar
problem with the CIMI frontend: the XML/JSON serializations are
determined by the CIMI standard. We've resorted to writing our own
support for serialization/deserialization, complete with a DSL that lets
us describe what they should look like for each class.
For the morbidly curious, the main pieces of code doing this are
schema.rb[1], which is the logic behind parsing/unparsing both JSON and
XML, and base.rb[2], which is the base class for all model classes. And
be warned, there are changes for these classes in the pipeline ...
David
[1] https://github.com/apache/deltacloud/blob/master/server/lib/cimi/models/schema.rb
[2] https://github.com/apache/deltacloud/blob/master/server/lib/cimi/models/base.rb
More information about the aeolus-devel
mailing list