0

I'm using grape gem; ref https://github.com/intridea/grape.

Could you show me how to build named path like "twitter_api_v1_statuses_path" ?

My code is as follows

module Twitter
  class API < Grape::API
    version 'v1', using: :header, vendor: 'twitter'
    format :json
    prefix :api

    resource :statuses do
      desc "Return a public timeline."
      get :public_timeline do
        Status.limit(20)
      end
    end
end
Ito Yoshiaki
  • 49
  • 1
  • 3

1 Answers1

0

I'm assuming that you want an URL like this http://yourdomain.com/api/v1/statuses/public_timeline. In this scenario, you have only one problem in your API class and it's related to the versioning strategy you've chosen. The :header strategy search for the API version in a specific header and that's not what you're looking for. Change it to :path.

module Twitter
    class API < Grape::API
        version 'v1', using: :path, vendor: 'twitter'
        format :json
        prefix :api

        resource :statuses do
            desc "Return a public timeline."
            get :public_timeline do
                Status.limit(20)
            end
        end
    end
end
Marlon
  • 888
  • 6
  • 12
  • The :header strategy was changed to :path, but I couldn't get named path of API in app/controllers/*** I added mount strategy in config/routes like `mount Twitter::API => '/'` My purpose is as follows in app/controllers/sample_controller.rb `redirect_to twitter_api_v1_statuses_path` – Ito Yoshiaki Dec 22 '14 at 02:27