How to get ALL of the URL parameters in a Sinatra app

necrobious picture necrobious · Feb 17, 2010 · Viewed 27.2k times · Source

Using the following Sinatra app

get '/app' do
  content_type :json
  {"params" => params}.to_json
end

Invoking:

/app?param1=one&param2=two&param2=alt

Gives the following result:

{"params":{"param1":"one","param2":"alt"}}

Params has only two keys, param1 & param2.

I understand Sinatra is setting params as a hash, but it does not represent all of the URL request.

Is there a way in Sinatra to get a list of all URL parameters sent in the request?

Answer

unclepotap picture unclepotap · Oct 17, 2012

Any request in rack

get '/app' do
  params = request.env['rack.request.query_hash']
end