美文网首页
Rails使用grape开发api,目录结构

Rails使用grape开发api,目录结构

作者: aston | 来源:发表于2014-10-04 18:59 被阅读0次

使用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 => '/'

相关文章

网友评论

      本文标题:Rails使用grape开发api,目录结构

      本文链接:https://www.haomeiwen.com/subject/dbwqtttx.html