0

私はブドウの宝石を使用しています。参照https://github.com/intridea/grape

「twitter_api_v1_statuses_path」のような名前付きパスを作成する方法を教えてもらえますか?

私のコードは次のとおりです

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
4

1 に答える 1

0

http://yourdomain.com/api/v1/statuses/public_timelineのような URL が必要だと仮定しています。このシナリオでは、API クラスに問題が 1 つだけあり、それは選択したバージョン管理戦略に関連しています。:header戦略は、特定のヘッダーで API バージョンを検索しますが、それは探しているものではありません。: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
于 2014-12-20T23:37:31.890 に答える