#322 RABL
RABL - Ruby API Builder Language - provides a DSL for generating JSON or XML responses in a Ruby application. Learn how to share and configure complex JSON data in this episode.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Thank you for making this! I'm a big fan of the RABL project and think they do an excellent job.
Also. Woot first comment.
I tried this..but seem to be getting a weird error:
Completed 406 Not Acceptable in 9ms...any ideas?
I'm using rails 3.0.5...
Check your request's headers. You might see this, for example, if you're sending Accept headers to set the version but your API is routing based on path.
Thanks for the episode on RABL.
It would be nice to have JSON output to be formatted in the casts. What about using https://github.com/rfletcher/safari-json-formatter ?
Great screencast, Ryan!
Thumbs up for this suggestion! :-)
I was just thinking: "It would be nice if Safari could render JSON in a more readable way... www.goo... oops" You beat Google! Great tip!
Is it possible to create something like this:
Where
message
andmeta
- is custom keys (not in AR). And all data goes underdata
key?Yes, take a look at using the
node
keyword because this allows for very flexible responses. Just added the beginning of a guide for it here: https://github.com/nesquena/rabl/wiki/Flexible-ResponsesThis is exactly thing I need! Thanks for your reply.
Thats's neat. I am trying to re-code some unfinished application using RABL.
Thanks for another great episode!
Have you had a look at https://github.com/josevalim/active_model_serializers
Thank you for the link to ActiveModel::Serializers! It is awesome. I've built the needed JSON outputs in 5 mins for our all entities.
Glad to see more people talking about json templating for building apis. Here's an alternative to rabl that we wrote at Zaarly called bldr https://github.com/ajsharp/bldr
Being forced to install a bloated (120+m) DivX player just to watch my beloved RailsCasts is not making me happy. It's probably not your doing, but please pass along the disgruntlement of at least one (and probably many more) viewers about this HUGE step backward by Sublime
VLC.. or download the mp4.. or click WebM in any browser that supports it...
Very nice Episode!
It would be nice if you could easily customize the xml output with CDATA for special characters :)
first off: I am using rails 2.1.1 and ruby 1.8.7. I have the gem installed so I'm pretty sure that is all setup.
But here is my issue:
map.ipad_push '/api/ipad/v1/push/user/:user_id.:format', :controller => 'api', :action => 'push'
I have my api_controller.rb, and an action defined in it called "push"
in views/api i have file push.json.rabl
But when I try to view the json, I get the "Missing template api/push.json.erb in view path /Users/pwgustafson/Desktop/HitFix/hitfix2/app/views"
I was able to get this working in another rails 3 app, so I'm curious if there might be some basic thing I'm doing wrong to get this working.
Can you try again with RABL 0.6.4 if you get a chance and followup?
@Ryan: excellent RailsCast, as always!
the following article from RABL's author Nathan Esquenazi is very interesting, and may be a good addition to the references section:
If you're using to_json, you're doing it wrong
As kind of an addendum to the link, at the time I wrote that (not too long ago) I saw honestly almost nobody talking about api (json) template building. At least not in my visible sphere.
Things have changed dramatically since then. Now with jbuilder, the revised json_builder, serializers, boxer, et al it seems that this space has gotten a lot of attention recently especially with the rise of Backbone. I consider this a very good thing. I think every api templater that has popped up has a valid use case and an interesting use case. Down with to_json :P
I know this is a few weeks old - but this railscast has been as indispensable as the casts on backbone. Thank you for showing me what I needed to use before I even realized it.
Yes personally using RABL with Backbone (or Spine) and also with https://github.com/gazay/gon has made for a great combination for my projects. Anyone reading this might find https://github.com/nesquena/rabl/wiki/Backbone-Integration and https://github.com/nesquena/rabl/wiki/Flexible-Responses useful as well.
I WISH I knew about this when I wrote my first API. I overrode to_json in all my models and WOW this would be so much better. Thanks for the awesome screencast.
I'm on the third iteration of an alpha release for a system that, by 1.0, has been publicly committed to implementation as a service-component architecture. What I've got now is the result of a series of increasingly rushed three-steps-forward-two-back iterations, with the apps mostly breaking their faces against data formatting/communication over the wire.
The effort has been going on for some four months now. The first iteration used Grape around a couple of core components. Since we lost half our development staff, those components have been subsumed into the "traditional" Rails apps that now exist.
I just spent a couple of hours poking around with a greenfield prototype using RABL and got functionality working that took the then-larger team almost two weeks to get right.
I'll definitely be following the RABL project and making use of it in future. Thanks for the as-always excellent Railscast, Ryan! My Pro subscription is some of the best-spent money I can think of lately!
I am trying to use RABL with a model structure using inheritance. I fail setting up a matching template.
Maybe you can take a look here.
I need a litte help.
Where is the rigth place to define the server's address for a remote json ?
tks.
Thanks for the video. It's awesome.
Is is possible to store the json output as variable value, apart from displaying it in a view?
Is this current best practice or is https://github.com/rails-api/active_model_serializers the way to go these days?
Depending on how custom you need the JSON, RABL or JBuilder are still used. I prefer JBuilder as it's a little bit more flexible for my needs. I needed custom keys that didn't depend on the model name. If however, you just want a simple data structure with model-name-based keys, then you should use ActiveModel Serializers
undangan pernikahan undangan pernikahan unik undangan pernikahan simple
Thanks for the episode.
Quite nice post actually.