I was trying to create an API using Grape. And for making this API work was referring to this website- One Grape API. I even saw these posts on stackoverflow but its not working. The code is as follows: /app/api/api.rb
class API < Grape::API
prefix 'api'
version 'v1', using: :path
format :json
mount Code::Coding
end
/app/api/code/coding.rb:
module Code
class Coding < Grape::API
resource :exam_questions do
desc "getting all the questions"
get do
ExamQuestion.first
end
end
end
end
/app/config/application.rb:
config.paths.add 'app/api', glob: '**/*.rb'
config.autoload_paths += Dir["#{Rails.root}/app"]
/app/config/routes.rb:
mount Coders::API => '/'
But I keep getting this error
Expected ../app/api/api.rb to define Api
Okay so now I moved the api files inside a folder named as Coders and there's no error. So the file structure is like this:
app/api/coders/api.rb
module Coders
class API < Grape:: API
#code goes here
end
end
And app/api/coders/code/coding.rb
module Coders
module Code
class Coding < Grape::API
resource :exam_questions do
desc "getting all the questions"
get do
ExamQuestion.first
end
end
end
end
end
Now I have tried almost all permutations and combinations to access it but I am unable to get the path where I can access the questions, it keeps showing 404 error.
Running rake routes gives: coders_api_api/ Coders::API
Is there any way to find out the links to access my methods.