Answer the question
In order to leave comments, you need to log in
How to split a class into multiple files in Ruby?
I understand with Grape and formed for myself an application structure similar to that described here ( repository ), only without using Rails. It turned out the following:
app/api/v1.rb
app/api/v1/product.rb
app/api/v1/review.rb
module API
class V1 < Grape::API
version 'v1', using: :path
content_type :json, 'application/json; charset=UTF-8'
prefix :api
format :json
before do
header['Access-Control-Allow-Origin'] = '*'
header['Access-Control-Request-Method'] = '*'
end
mount Product
mount Review
end
end
module API
class V1::Product < Grape::API
resource :products do
get do
%w(Cofee Tea Rice Meat)
end
end
end
end
module API
class V1::Review < Grape::API
resource :reviews do
get do
"This is review"
end
end
end
end
module API
class V1 < Grape::API
class Product < Grape::API
...
end
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question