On Tue, Apr 09, 2013 at 09:11:46PM +0530, Arvind Creatrix IT Soft wrote: > Hi
Hallo Arvind. > > With ref to the discussion- I was already planning to work on creating an API > over the core Delta Cloud code as I need it in a number of my projects. > > I suggest the following means to do this, in as painless a manner as > possible-- > > (1) Use Rails and RABL--> https://github.com/nesquena/rabl to generate the API > (2) Use the VersionCake gem for versioning( > https://github.com/bwillis/versioncake) > (3) Controllers are set up in an hierarchy where you have one BaseController > which contains this authentication logic (as a before_filter) and then the > other controllers inherit from that. If you have any other helpers, they > would go in this controller too. > (4) For authorization, use CanCan.(https://github.com/ryanb/cancan) It's > README and Wiki are great sources of information on how to use it. I am experimenting with a cloud broker concept and actually I am trying out Rabl on top of Sinatra w/o Padrino as this gives me most of what I need and stays sort-of lightweight especially when comparing with Rails. So you can provide a recommendation for Rabl? Do you have personal good experience with it? Then what do you use for parsing of POST data? Is there some counterpart of Rabl that would parse XML and JSON based on similar rules and give me a nice Ruby hash and a decent list of errors in case of any? I also wonder what type of project you have that use DeltaCloud. Can you share such information? What parts of DeltaCloud do you use most? > > Finally, here is some helpful text from the RABL docs--> > > Once you have installed RABL (explained above), you can construct a RABL view > template and then render the template from your Sinatra, Padrino or Rails > applications from the controller (or route) very easily. Using Padrino as an > example, assuming you have aPost model filled with blog posts, you can render > an API representation (both JSON and XML) by creating a route: > > # app/app.rb > get "/posts", :provides => [:json, :xml] do > @user = current_user > @posts = Post.order("id DESC") > render "posts/index" > end > Then we can create the following RABL template to express the API output of > @posts: > > # app/views/posts/index.rabl > collection @posts > attributes :id, :title, :subject > child(:user) { attributes :full_name } > node(:read) { |post| post.read_by?(@user) } > Which would output the following JSON or XML when visiting > http://localhost:3000/posts.json > > [{ "post" : > { > "id" : 5, title: "...", subject: "...", > "user" : { full_name : "..." }, > "read" : true > } > }] > This is an easy way to create a API library that has its own versioning- and > at the same time it basically just uses the core code in the Delta Cloud > library itself. > -- Martin Povolny <mpovo...@redhat.com> tel. +420777714458