Grape::JSONAPIResources
Use jsonapi-resources with Grape!
Installation
Add the grape
and grape-jsonapi-resources
gems to Gemfile.
gem 'grape'
gem 'grape-jsonapi-resources'
Usage
Require grape-jsonapi-resources
Tell your API to use Grape::Formatter::JSONAPIResources
class API < Grape::API
format :json
formatter :json, Grape::Formatter::JSONAPIResources
end
Use render
to specify JSONAPI options
get "/" do
user = User.find("123")
render user, include: ["account"], context: { something: :important }
end
Credit
Code adapted from grape-active_model_serializers