Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Flexible Responses

nesquena edited this page · 6 revisions

RABL allows for varying levels of flexibility depending on the needs of an API. The most extreme of this flexibility is constructing responses not based on a record at all:

object false # uses no record

node(:message) { "..." }
node(:data) do
  @objects.map { |o| { :name => o.name } }
end
node(:meta) { "..." }

Returns:

{
  message: "...",
  data: [{"name" : "foo" }],
  meta: "..."
}

You can also use RABL partials for much more powerful customization:

object false # uses no record

node(:message) { "..." }
node(:data) do
  partial("rabl/template", :object => @objects)
end
node(:meta) { "..." }

Note that RABL doesn't work with hash data objects. Use OStruct instead as explained in this post.

Also take a look at Using Layouts in RABL as well as other Tips and Tricks.

Something went wrong with that request. Please try again.