Skip to content

cdunn/grape-jsonapi-resources

Repository files navigation

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

About

Serialize objects via JSONAPI::Resources for Grape API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages