I have created ApiBuilder which is a Ruby on Rails plugin/template engine
that allows for multiple formats being laid out in a single specification,
currently XML and JSON.
You lay out your spec in one file and it automatically generates both XML
and JSON from that specification.

Install it using

$ rails plugin install git://github.com/lassebunk/api_builder.git

And then, in e.g. *app/views/api/users/index.apibuilder*:

array :users do
@users.each do |user|
element :user do
id @user.id
name @user.name
end
end
end

Returns:

[
{
"id": 1234,
"name": "Peter Jackson"
},
{
"id": 1235,
"name": "Marilyn Monroe"
}
]

And the equivalent XML.

In *app/views/api/users/show.apibuilder*:

element :user do
id @user.id
name @user.name
address do
street @user.street
city @user.city
end
array :interests do
@user.interests.each do |interest|
element :interest, interest.name
end
end
end

Returns:

{
"id": 1234,
"name": "Peter Jackson",
"address": {
"street": "123 High Way",
"city": "Gotham City"
},
"interests": [
"Movies",
"Computers",
"Internet"
]
}

And the equivalent XML.

You can then call your API like this:

http://example.com/api/users?format=json

or

http://example.com/api/users?format=xml

and so on.

What do you think?

More information at GitHub (https://github.com/lassebunk/api_builder) and my
website (
http://lassebunk.dk/2011/09/12/introducing-apibuilder-xml-and-json-builder-in-one/
).

/Lasse Bunk

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Rajarshi at Sep 20, 2011 at 4:30 am
    thanks
    On Tue, Sep 20, 2011 at 2:11 AM, Lasse Bunk wrote:

    I have created ApiBuilder which is a Ruby on Rails plugin/template engine
    that allows for multiple formats being laid out in a single specification,
    currently XML and JSON.
    You lay out your spec in one file and it automatically generates both XML
    and JSON from that specification.

    Install it using

    $ rails plugin install git://github.com/lassebunk/api_builder.git

    And then, in e.g. *app/views/api/users/index.apibuilder*:

    array :users do
    @users.each do |user|
    element :user do
    id @user.id
    name @user.name
    end
    end
    end

    Returns:

    [
    {
    "id": 1234,
    "name": "Peter Jackson"
    },
    {
    "id": 1235,
    "name": "Marilyn Monroe"
    }
    ]

    And the equivalent XML.

    In *app/views/api/users/show.apibuilder*:

    element :user do
    id @user.id
    name @user.name
    address do
    street @user.street
    city @user.city
    end
    array :interests do
    @user.interests.each do |interest|
    element :interest, interest.name
    end
    end
    end

    Returns:

    {
    "id": 1234,
    "name": "Peter Jackson",
    "address": {
    "street": "123 High Way",
    "city": "Gotham City"
    },
    "interests": [
    "Movies",
    "Computers",
    "Internet"
    ]
    }

    And the equivalent XML.

    You can then call your API like this:

    http://example.com/api/users?format=json

    or

    http://example.com/api/users?format=xml

    and so on.

    What do you think?

    More information at GitHub (https://github.com/lassebunk/api_builder) and
    my website (
    http://lassebunk.dk/2011/09/12/introducing-apibuilder-xml-and-json-builder-in-one/
    ).

    /Lasse Bunk

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 19, '11 at 8:42p
activeSep 20, '11 at 4:30a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Rajarshi: 1 post Lasse Bunk: 1 post

People

Translate

site design / logo © 2021 Grokbase