I’m moving an API endpoint from an Express service to a Ruby on Rails service. In Express, when multiple values are provided for the same query parameter, for example http://localhost:3002/api/resource?include=foo&include=bar, Express treats them as an array. The query parameters to the previous endpoint would be { include: ['foo', 'bar'] }.
The default behavior I’m seeing in Ruby on Rails is to override the previous query param when multiple query params are used with the same key. For example, the previous endpoint’s query params would be translated as { include: 'bar' }. Is it possible to change this behavior to allow for an array of values instead of overriding the previous value?
Since this is a preexisting API endpoint, I cannot change the URL to fix this problem. I know that http://localhost:3002/api/resource?include[]=foo&include[]=bar would work, but this would be a breaking change to the API.
>Solution :
CGI::parse request.query_string