Question

I'm using JSON to communicate between my rails app and iOS via RestKit (Thanks Blake Watters) so I'm doing a simple light private API Rails-iOS integration.

It would be great t just use respond_to format.json for every controller, but I sort of ruled out this approach because I want distinct separation between API/web interface.

What's a good and DRY approach to writing a separate controller to handle API?

Right now, I'm thinking of creating a namespace called api and then creating controllers (e.g. shop, products) under the namespace. Each of these controllers will then have its own methods(create, destroy etc)

Was it helpful?

Solution

You idea about "creating a namespace called api and then creating controllers" is right. I'm using this approach in several projects. The only drawback is that anything overloading your API will overload your website as well.

You could also split API and website into two separate Rails applications. In this case make sure you are sharing your Rails models and helpers..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top