You can’t directly do what you want. When describing the route, Sinatra treats ?
as defining an optional parameter, and doesn’t provide a way to escape it.
In a url a ?
separates the path from the query string, and Sinatra only uses the path when matching routes. The contents of the query string are parsed and available in params
, and the raw string is available as request.query_string
.
Your url scheme seems rather unusual, but one possibility if you want to avoid checking the query_string
in the actual route could be to create a custom condition to apply to the routes, and check in there:
set(:query) { |val| condition { request.query_string == val } }
get '/:id', :query => 'inspect' do
# ...
end
get '/:id', :query => 'last' do
# ...
end
get '/:id' do
# ...
end