使用grape开发api结构如下:
app
|_ api
|_ v1
|_ api.rb
|_application.rb
|_some.rb
|_entities
api.rb文件内容
module V1
class API <Grape::API
mount V1::Some
end
end
application.rb
module V1
class Application < Grape::API
def self.inherited(child)
super
child.format :json
child.prefix "api"
child.version 'v1', :using => :path
child.helpers do //helper定义
def strong_params
ActionController::Parameters.new(params)
end
end
end
end
end
some.rb
module V1
class Some< Application
end
end
rails的config/routes.rb
# api
mount V1::API => '/'