I’m building a Rails app, which I’ll also develop a mobile app for. I’m trying to make it RESTful and create an API that all front-end views will communicate through to the back-end. Is there a way to have the controller talk to the API instead of directly to the models? In that way, I can ensure all front-end accesses are controlled by the API.
EDIT:
I found two articles that talk about this. But I’m trying to find a way to precisely separate the API from the website’s main controllers and views. Is there a way to have my controllers and views talk directly to the API, instead of the model?
http://engineering.gomiso.com/2011/05/16/if-youre-using-to_json-youre-doing-it-wrong/
http://blog.gomiso.com/2011/06/27/building-a-platform-api-on-rails/
http://www.rubyflow.com/items/5649-rabl-the-ruby-api-templating-language
In general the controllers are the API.
However what you are describing is a service layer. There is a railscasts episode on this that will likely assist you in this.
http://railscasts.com/episodes/398-service-objects