Я использую Rails 6 с Grape в качестве API. Я новичок в Grape и пытаюсь узнать, как добавить новую конечную точку с помощью Grape. Идея состоит в том, чтобы получить конечную точку индекса, которая вложена в v1 / users / index
Вот моя структура:
app/
controllers/
api/
root.rb - API::Root
v1/
base.rb - API::V1::Base
users/
base.rb - API::V1::Users::Base
index.rb - API::V1::Users::Index
api/root.rb
module API
class Root < Grape::API
default_format :json
prefix :api
# exception handling
include Rescuers
# helpers
helpers ::API::Helpers::ParamsHelper
# core API modules
mount V1::Base
end
end
api/v1/base.rb
:
module API
module V1
class Base < Root
version 'v1', using: :path
content_type :json, 'application/vnd.api+json'
# mount resource modules
mount V1::Users::Base
end
end
end
api/v1/users/base.rb
:
module API
module V1
module Users
class Base < Grape::API
version 'v1', using: :path
content_type :json, 'application/vnd.api+json'
# mount resource modules
mount Users::Index
end
end
end
end
api/v1/users/index.rb
:
module API
module V1
module Users
class Index < Grape::API
desc 'Test'
get do
head 200
end
end
end
end
end
Вот мои маршруты:
Rails.application.routes.draw do
# API
scope :api do
mount API::Root, at: '/'
end
end
Я хочу, чтобы этот index.rb
был в моих маршрутах как GET v1/users/index
, но когда я набираю rake routes
, я его не вижу. Это ничего не должно делать, я хочу понять, каковы основные требования, когда дело доходит до создания конечной точки с помощью Grape.