lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Building URLs with globbed routing

Open jwoertink opened this issue 1 year ago • 4 comments

I'm pretty sure this isn't possible at the moment, or maybe I'm just missing it, but I don't believe there's a way currently to build a URL from an action with globbed routing.

class Reporting::Index < BrowserAction
  get "/reporting/*:filter" do
    plain_text filter
  end
end

# Writing in a spec 
client = ApiClient.new
# there's no way to set that filter
response = client.exec(Reporting::Index.with("???"))

jwoertink avatar Oct 30 '24 19:10 jwoertink

There was a whole discussion about this ... what ... 5 years ago? (😱)

Amber has this in amber-router, but it's a surprisingly complicated problem to solve with speed. https://github.com/amberframework/amber-router/blob/master/spec/amber_router/route_set/matching/glob_matching_spec.cr

robacarp avatar Oct 31 '24 00:10 robacarp

I may have worded the issue weird. Lucky supports glob routing already. The issue is if you want to construct the route in a spec, there's not a way to do that from the action class. Currently you have to do client.get("/the/path").

jwoertink avatar Oct 31 '24 01:10 jwoertink

Ohhhh my mistake sorry!

robacarp avatar Oct 31 '24 15:10 robacarp

I started working on this, but it's sort of an exhausting issue 😫 If anyone is bored and feels like taking it on, you'll need to start here

https://github.com/luckyframework/lucky/blob/e161fc52f88a2047e6aa699089bf1466426c7514/src/lucky/routable.cr#L199

It has to be accounted for in

  • url_without_query_params
  • path_without_query_params
  • route
  • with
  • both path_from_parts

There's TONS of duplication, but keeping macros DRY is super difficult because context starts to change.

jwoertink avatar Apr 10 '25 22:04 jwoertink