How to split things up in a grape api app?

后端 未结 2 516
夕颜
夕颜 2021-02-02 16:19

In every examples I see, people only implement one giant api.rb file. Ex:

  • intridea/grape
  • bloudraak/grape-sample-blog-api
  • djones/grape-goliath-exa
2条回答
  •  孤独总比滥情好
    2021-02-02 16:51

    The class in post.rb should be Post, not API. Then you can mount the Post API inside class API.

    class API < Grape::API
      mount Blog::Post => '/'
    end
    

    To avoid confusion I would put Post in a Resources namespace, too or rename it to PostAPI.

提交回复
热议问题