RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

RABL, The Ruby API Templating Language

Inspired while building a public API and by frustrations with JSON generating libraries like tequila and json builder, I have created the RABL templating engine which allows you to define JSON and XML APIs in a clean, simple ruby DSL. a The gem also removes code duplication allowing template partials and inheritance. Works with Rails 2.X, Rails 3.X, Sinatra and Padrino. Benchmarks are forthcoming.

Comments

Nice gem you have here! I am the author of JSON Builder, just curious, you say you had frustrations with the gem but there were no tickets from you on GitHub or any sort of indicator of what you were having a problem with. Can't make the gem any better that way! What were you having a problem with?Garrett - April 12, 2011 16:16
Good question Garrett. You are right that I didn't raise any issues. With JSON Builder (which I think is a very good project), the issue was simply the verbosity and the need to explicitly declare all the data.

I wanted a simple dsl that describes the model data rather than a 'builder' explicit format. The difference between


json.name "Garrett Bjerkhoel"
json.address do
json.street "1143 1st Ave"
json.street2 "Apt 1"
json.city "New York"
json.state "NY"
json.zip 10065
end


and


object @user
code(:name) { |u| u.first_name }
child @address => :address do
attributes :street, :city, :zip, :state
end


I wouldn't say one is necessarily better than the other, but for my needs I wanted the less verbose and more 'intelligent' dsl rather than a full builder style framework.nesquena - April 12, 2011 17:44
I screwed up the pre formatting on those code blocks but I hope the comment makes sense. I didn't feel it was something that could be addressed in an issue per se. Would you agree? It was more of a early design choice. It is also why I linked to tequila. I wanted a hybrid between the projects.nesquena - April 12, 2011 17:46
All good! That's the beauty of Ruby :) I just really liked how Builder gave you full control, and I basically mimicked that.

I like the direction yours is going and might just use that, would definitely like some Rails 3 support, but you know that.

Good luck! Nice gem.Garrett - April 13, 2011 04:01
Thanks, glad you like the Gem. There is not full Rails 3 support and XML Serialization support.nesquena - April 13, 2011 07:34
Sorry of course I typo that. I have added full Rails 3 support now.nesquena - April 13, 2011 07:35
I love RABL! I've written up a tutorial on writing an app using RABL and some of the great features. Hope it helpsNick Rowe - June 25, 2011 00:21

Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!