0.0
No commit activity in last 3 years
No release in over 3 years
Middleware to convert params to snake_case. Useful for APIs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0

Runtime

>= 5.0
 Project Readme

SnakyParams

Gem Version

SnakyParams is Rack middleware for Rails that automatically converts request parameter keys to snake_case.

This is useful if you Rails app is being used as an API for a front-end application written in any other language (e.g. JavaScript). In Ruby and Rails, the widely adopted naming convention is to use snake_case for variables, keys etc. Popular JavaScript style guides (such as the Airbnb JavaScript Style Guide) tend to recommend camelCase. This gem allows you to use snake_case in all Ruby/Rails code without having to worry about converting the case of parameter names or having non-conventional names.

Installation

  1. Add this line to your application's Gemfile and execute bundle install:
gem 'snaky_params'
  1. Add this line as the last config to config/application.rb:
config.middleware.use SnakyParams::Middleware

Usage

Conversion is automatic. All query, post, put and patch parameter keys in requests to your Rails application are converted to snake_case.

Example:

  • searchQuery becomes search_query
  • FirstName becomes first_name
  • last-name becomes last_name
  • monthlyOrYearlySalary becomes monthly_or_yearly_salary

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/uxman-sherwani/snaky_params.

License

The gem is available as open source under the terms of the MIT License.