With Sinatra i can pass multiple "unknown" params to a route by using:
get '/say/*/to/*' do
# matches /say/hello/to/world
params[:splat] # => ["hello", "world"]
end
How to do the same in Espresso?
Routes in Espresso are regular Ruby methods.
So if the method works in Ruby, the route will work in Espresso.
What you are trying to achieve is offered by Ruby for free.
Just define a Ruby method with predefined arguments:
require 'e'
class App < E
map '/'
def say greeting = :hello, vertor = :to, subject = :world
"say #{greeting} #{vertor} #{subject}"
end
end
# some testing
require 'sonar' # same as rack-test but a bit better
include Sonar
app App # letting Sonar know that app to test
puts get('/say').body
# => say hello to world
puts get('/say/Hi').body
# => say Hi to world
puts get('/say/Hi/from').body
# => say Hi from world
puts get('/say/Hello/from/Espresso').body
# => say Hello from Espresso
puts get('/say/Goodbye/to/Sinatra').body
# => say Goodbye to Sinatra
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With