This gem lets your API users pass in and receive camelCased or dash-cased keys, while your Rails app receives and produces snake_cased ones.
-
Add this to your Gemfile and then
bundle install
:gem "olive_branch", git: 'https://github.com/ericproulx/olive_branch.git'
The middleware will be automatically added through Railtie
Include a X-Key-Inflection
header with values of camel
, dash
, or snake
in your JSON API requests.
# config/initializers/olive_branch.rb
OliveBranch.configuration do |config|
config.camelize = # your camelize function ( Default: string.underscore.camelize(:lower))
config.dasherize = # your dasherize function ( Default: string.dasherize)
config.content_type_check = # your content type check function ( Default: 'application/json')
config.default_inflection = # if you don't want to include the header key in every request, you can default an inflection
config.header_key = # your header key ( Default: HTTP_X_KEY_INFLECTION )
end
OliveBranch is released under the MIT License. See MIT-LICENSE for further details.
Visit code.viget.com to see more projects from Viget.