【发布时间】:2017-11-23 05:21:26
【问题描述】:
我使用 gem,grape 作为 api。
我尝试通过命令rake grape:routes获取api url
namespace :grape do
desc "routes"
task :routes => :environment do
API::Root.routes.map { |route| puts "#{route} \n" }
end
end
但我得到了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
【问题讨论】:
标签: ruby-on-rails api grape