0.01
No release in over 3 years
Low commit activity in last 3 years
Rack middleware for Rails that automatically converts request param keys to snake_case and response keys to camelCase helping you maintain a consistent code style in your Ruby and JavaScript code
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0

Runtime

>= 4.0
 Project Readme

SnakyCamel

Build Status Code Climate

SnakyCamel is Rack middleware for Rails that automatically converts request parameter keys to snake_case and response keys to camelCase.

This is useful if you Rails app is being used as an API for a JavaScript frontend. 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 and camelCase in JavaScript 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_camel'
  1. Add this line as the last config to config/application.rb:
config.middleware.use "SnakyCamel::Middleware"

Usage

Conversion is automatic. All parameter keys in RESTful requests to your Rails application are converted to snake_case. All JSON response keys from your Rails application are converted to camelCase.

Example:

  • Your application receives a request to yourapp.com/search?searchQuery=cobra. In the params hash in your Rails controller, the param key name will be search_query.
  • You render JSON with your controller with this code: render json: { search_results: ['dromedary'] }, status: :ok. The actual response is converted to { searchResults: ['dromedary'] }.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/p4sh4/snaky_camel.

License

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