cdunn / grape-jsonapi-resources

Serialize objects via JSONAPI::Resources for Grape API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:MIT License


Languages

Language:Ruby 100.0%