I'm using grape to create an api in rails. The project is still pretty fresh but I've hit a blocking point so far with my routes.
I added an test endpoint to see if my versions were working together and they were
my config/routes.rb
file
Rails.application.routes.draw do
mount Root => '/'
end
my app/api/root.rb
file
require "grape"
class Root < Grape::API
format :json
mount Test::API
end
my app/api/test/api.rb
file
require "grape"
module Test
class API < Grape::API
get :world do
{
"response"=>"hello world!",
"name"=>"it is i"
}
end
end
end
and my api/test/api_spec.rb
file
require 'rails_helper'
describe 'Endpoints' do
context 'when the endpoint "world" is hit' do
context 'the response' do
let(:res) { JSON.parse(response.body)['response'] }
it 'returns hello world' do
get '/world'
expect(res).to eq 'hello world!'
end
end
end
end
All of this worked perfectly well, so I tried adding another mount to my app/api/root.rb
file
require "grape"
class Root < Grape::API
format :json
mount Test::API
mount Endpoints::TodoAPI
end
and my app/api/endpoints/todoapi.rb
file
require "grape"
module Endpoints
class TodoAPI < Grape::API
end
end
when I tried to run my api/test/api_spec.rb
file, I suddenly started getting an error
Failure/Error: mount Endpoints::TodoAPI
NameError:
uninitialized constant Endpoints::TodoAPI
mount Endpoints::TodoAPI
^^^^^^^^^
Did you mean? Endpoints::Todoapi
I tried to make the TodoAPI
look exactly like the api
file, and comment out api
's mount but I keep getting the same error.