Rack Adequate Json
Rack Middleware to reduce size of json payload - Allows clients consuming json api to select attributes within payload
Installation
Add this line to your application's Gemfile:
gem 'rack-adequate-json' , require: 'rack/adequate_json'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rack-adequate-json
Configure
Rails
#config/application.rb
module AppName
class Application < Rails::Application
# Middleware options
# root: the root key for the json payload , default: nil
# target_param: query param of filter fields , default: 'fields'
config.middleware.use 'Rack::AdequateJson' , { root: 'data' }
end
end
Sinatra
require 'rack/adequate_json'
class AppName < Sinatra::Base
configure do
# Middleware options
# root: the root key for the json payload , default: nil
# target_param: query param of filter fields , default: 'fields'
use Rack::AdequateJson , { root: 'data' , target_param: 'select' }
end
end
Contributing
- Fork it ( http://github.com//rack-adequate-json/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request