I have a requirement where user can pass url in this format:
http:site.com/[action]/[subject]?[option]=[value]
for example all of the below are valid urls:
http://example.com/trigger/a/b/c
http://example.com/trigger/a
http://example.com/trigger/a/b?something=value
http://example.com/trigger/any/thing/goes/here
I have a grape
resource like this:
class Test < Grape::API
params do
optional :option, type: String
end
get '/trigger/:a/:b/:c' do
{
type: 'trigger',
a: params[:a],
b: params[:b],
c: params[:c],
option: params[:option]
}
end
end
So, If I visit http://example.com/1/2/3/option=something
then I will get
{
"type": "trigger",
"a": "1",
"b": "2",
"c": "3",
"option": "something"
}
Expected Behavior:
Use should be able to provide anything after /trigger/
http://example.com/any/thing/goes/here/1/2/3?other=value&goes=here
Update:
I found this solution (How do we identify parameters in a dynamic URL?) for rails route, I want this behavior in grape
.
thanks