1
我使用寶石,葡萄爲api。 我試圖通過命令rake grape:routes
如何通過葡萄API獲得路線
namespace :grape do
desc "routes"
task :routes => :environment do
API::Root.routes.map { |route| puts "#{route} \n" }
end
end
獲得API網址,但我得到了由rake grape:routes
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
#<Grape::Router::Route:0x007f9040d13878>
...
我想是這樣的。
version=v1, method=GET, path=/services(.:format)
version=v1, method=GET, path=/services/:id(.:format)
...
我的葡萄實現如下。這很好。
module API
class Root < Grape::API
version 'v1', using: :path
format :json
helpers Devise::Controllers::Helpers
mount API::Admin::Services
end
end
module API
class Services < Grape::API
resources :services do
resource ':service_id' do
...
end
end
end
end
謝謝。它運作良好! –