How to split things up in a grape api app?

后端 未结 2 515
夕颜
夕颜 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.

    0 讨论(0)
  • I found it not working for path prefix:

    mount Blog::Post => '/blog'
    

    doesn't work if you want have prefix the path.

    use

    namespace :blog do
       mount Blog::Post
    end
    

    Hope it helps!

    0 讨论(0)
提交回复
热议问题