Reputation: 2151
I am doing research on the best way to build a platform API along side my Ruby on Rails application. I came across this question which references ticketee, an example application that was written for Rails 3 in Action. I was looking at the API they have built and I notice they did not use "respond_to" or any type of JSON generating functions in their Ruby on Rails stack to support their API. They have actually built their API using Sinatra, outside of Ruby on Rails. Is this best practice? Does this not require maintaining two code bases essentially? Maybe there is some link I am missing?
As a followup question if this is the best practice and does not require a developer to maintain two code bases, what are the pros of using Sinatra instead of the "respond_to" methods or some other type of JSON generation inside the Rails controllers?
Upvotes: 2
Views: 298
Reputation: 107728
We do use respond_to
for the first version of the API in Chapter 13, but to demonstrate how to mount a Rack app in Chapter 18, we built a Sinatra app for that. There's no particular benefit to doing it this way, it was more to demonstrate that a) there's more than one way to skin the API cat and b) how to mount an application into Rails.
You wouldn't have to maintain a separate codebase so to speak, as the Sinatra app would be inside your Rails application, in the lib
directory. It would be the same as if the V2 of the API were just inside another directory of app/controllers/api/v2
or something similar.
Upvotes: 4