rails-api.md (RAILS JSON-API)#

Gemfile
> gem 'jsonapi-resources' in lieu of 'active_model_serializers'

config/environments development:

config.eager_load = true
config.consider_all_requests_local = false
app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery with: :null_session
end

create models#

User / Post / Comments

create controllers#

rails g controller Users rails g controller Posts

change both controllers to inherit from JSONAPI::ResourceController

class PostsController < JSONAPI::ResourceController
# auto respond to REST actions
end

md app/resources
touch app/resources/user_resource.rb
touch app/resources/post_resource.rb

class UserResource < JSONAPI::Resource
  attributes :name (attribs to expose)  
  has_many :posts
end


class PostResource < JSONAPI::Resource
  attributes :title, :content (attribs to expose)  
  has_one :user
  filter :user
end

Routes - different to normal#

routes.rb
#
jsonapi_resources :users
jsonapi_resources :posts