Providing a web service API in ROR 3

I would really like to receive tips on how to best demonstrate certain functionality from my site using the service API .. from my Internet searches I found that ActionWebService used certain functions in this direction, but was deprecated in the latest version of rails.

To develop a bit, I would like to create an iPhone application that connects to my current rails website .. ideally, an API services model that contains a bunch of functions that will be displayed in HTTP: /// Services, for example, where everything is, I've ever needed an iPhone for, so these Services features capture data from other models and simply offer them in an open API.

Looking for advice if I have the right approach here and what is the syntax for providing an API in rails?

Thank!

+3
source share
1 answer

Rails makes this really easy, really. By default, it provides XML endpoints. You can expose JSON just as easily (and, for iPhone, you should use JSON as it is easier to parse). Plus, he does it RESTfully. You should not add an API controller - just use the controllers that you already have for your resources.

In your block, respond_toyou should already see the code for XML. For JSON, just add the following:

format.json { render :json => @item, :status => :created, :location => @item }

Grab this something like RestKit on the iPhone, and you can easily create an iPhone application that communicates with the Rails application.

0
source

All Articles