I am working on an app that includes an API
that is using the grape
gem.
Here is my Root
Class:
module API
class Root < Grape::API
rescue_from :all do |e|
Rack::Response.new(
[ "Error: #{e.message}" ],
500,
{ "Content-type" => "text/error" }
).finish
end
prefix "api"
version 'v1', using: :path
format :json
error_format :json
mount ::API::ServiceRequests
end
end
Here is how I am mounting it in routes:
mount API::Root => '/'
The error I am receiving is:
routes.rb:45:in
block in ': uninitialized constant API (NameError)`
The files are structured like app/api/root.rb
and I have this bit of code in my application.rb
to load in the files:
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
app/api/v1/my_endpoint
prefixed asAPI::V1::MyEndpoint
. Moving it toapp/api/api/v1/my_endpoint
solved my problem. This seems pretty srange to me, but I guess this shows I should give a more specific name to the api, likeapp/api/github/v1/my_endpoint
orapp/api/google/v1/my_endpoint
, etc. – Densmore