How can we split grape api resources into multiple files?

Hey. I am developing a simple api in ruby ​​using intridea grape. Say we have this:

class API_v1 < Grape::API resource :foo do end resource :bar do end end 

How can I make it so that the declaration for :foo and :bar in separate files? Basically, I wanted to know if it is possible to have something similar to rails controllers, where there are several files for organizing the code.

I hope someone can give me an idea of ​​how to achieve this.

+4
source share
2 answers

Ruby has public classes , so you can just move them to separate the files.

 # foo.rb class API_v1 < Grape::API resource :foo do end end # bar.rb class API_v1 < Grape::API resource :bar do end end 
+8
source

README recommends using mount :

 class Foo < Grape::API resource :foo ... end class Bar < Grape::API resource :bar ... end class API < Grape::API mount Foo mount Bar end 
+8
source

All Articles