ruby - Trouble mounting multiple Grape APIs in Rails -


i have 2 apis i'm trying mount in rails app-- 1 called 'v1' , called 'twilio'. each api composed of multiple files, want each have own folder. inside app/api directory, have 2 folders--'v1' , 'twilio'--and file called 'api.rb' trying use mount 2 api's. it's contents are:

module api   class v1 < grape::api     prefix "api"     format :json     mount api::root => '/v1'   end    class twilio < grape::api     prefix "twilio"     format :xml     mount api::twilio_api => '/twilio'   end end 

in 'v1' directory, have file called 'root.rb' begins follows:

module api   class root < grape::api     version 'v1', :using => :header     ... 

and in 'twilio' directory, have file called 'twilio_api.rb' begins as:

module api   class twilio_api < grape::api     version 'v1', :using => :header     ... 

my routes file has:

mount api::v1 => "/" mount api::twilio => "/" 

when start rails server, i'm getting error:

`load_missing_constant': expected [my rails app]/app/api/v1/root.rb define root (loaderror) 

i don't understand this, since root.rb define root class. appreciated.

in grape can mount multiple apis in one. means can have 1 "base" class apis , mount other it.

files structure:

app/   api/     v1/       v1_api.rb     twilio/       twilio_api.rb     api.rb 

app/api/api.rb:

require 'v1/v1_api' require 'twilio/twilio_api'  module api   class base < grape::api     mount api::v1     mount api::twilio   end end 

app/api/v1/v1_api.rb:

module api   class v1 < grape::api     prefix "v1"     format :json      :hello       { text: 'hello v1' }     end   end end 

app/api/twilio/twilio.rb:

module api   class twilio < grape::api     prefix "twilio"     format :xml      :hello       { text: 'hello twilio' }     end   end end 

config/routes.rb:

mount api::base => '/api' 

restart rails server , you're go. should able autoload files app/api/twilio , app/api/v1 directories, won't have require them.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -