3

I'd like to open my Rails 2.3 app (hosted on Heroku) to developers. I thought of two ways of doing this:

  1. Using the respond_to |format| of the app, and a before_filter only allowing authorized developers API keys
  2. Using a second Heroku account dedicated to the API, sharing the original app's database. Now, what would be better: Rails, Sinatra, or Grape?

I know this is a vague question. Do you have any good articles or architectural patterns that could help me?

Thanks,

Kevin

dB.
  • 4,700
  • 2
  • 46
  • 51
martini-bonanza
  • 1,515
  • 3
  • 18
  • 33

2 Answers2

7

We use Grape. It's simple and allows much cleaner separation and semantics. The API is not really a controller.

dB.
  • 4,700
  • 2
  • 46
  • 51
4

I would add a new route

website.com/api/widget/

website.com/api/another_service/

And make a controller where seems natural under the API rout.

I would then make a module with before filters that checked however you want to check API keys.

class WidgetController < ActionController::Base
    include 'api_keyable'
    :before_filer :validate_api_key

    def create
        #However you create a widget from the params.
        # respond to XML, YAML, JSON, whatever
    end

end

if you later find you want to handle website.com/api/widgets on one app and website.com/api/wadgets on the other, your end users will never know and your code shouldn't need to change much.

EnabrenTane
  • 7,428
  • 2
  • 26
  • 44