Rails Nested Resource Issues

Dmitri Dolguikh dmitri at redhat.com
Fri Sep 21 10:32:24 UTC 2012


On 21/09/12 11:07 AM, Martyn Taylor wrote:
> On 09/20/2012 08:50 PM, David Lutterkort wrote:
>> 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
>>
> Thanks for this.
>
> Writing our own methods for unmarhalling content was one of the 
> possible approaches we were looking at.  Though it does bypass some of 
> the nice features of rails such as the abstraction of content-types.  
> I'm hoping we can catch the problem a bit further down the stack 
> possibly as Jiri suggested and modify params hash.
>
> CIMI is a good case example of when it's not possible to just accept 
> rails API preference.  I was getting some questions earlier on why 
> this is necessary.
>
> Martyn
>
>
>

There's also RABL [1] for "controlled serialization". I know Foreman 
folks are using it, perhaps Ohad (cc'd) can talk about his team 
experiences with it?

-d


[1] https://github.com/nesquena/rabl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/aeolus-devel/attachments/20120921/4f947a19/attachment.html>


More information about the aeolus-devel mailing list