How to add an open API to a Rails application?

I would like to open the Rails 2.3 application (hosted on Heroku) for developers. I thought of two ways of doing this:

  • Using response_to | format | applications, and before_filter allows authorized API API keys
  • Using Heroku's second API account, sharing the original application 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?

Thank,

Kevin

+3
source share
2 answers

. . API .

+7

website.com/api/widget/

website.com/api/another_service/

, API-.

, , API.

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

website.com/api/widgets - website/api/wadgets, , , .

+4

Source: https://habr.com/ru/post/1781224/


All Articles