Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to wild-carded segments in a path #660

Open
rssdev10 opened this issue Aug 1, 2023 · 4 comments
Open

Improvements to wild-carded segments in a path #660

rssdev10 opened this issue Aug 1, 2023 · 4 comments

Comments

@rssdev10
Copy link

rssdev10 commented Aug 1, 2023

In some cases, it is convenient to have a mechanism for processing parts of a path. E.g. I want to have a hierarchical processing of the path endingphotos/*other. This route would match photos/12 or /photos/long/path/to/12, setting other-segment to "12" or "long/path/to/12".

This way may be used for organizing access to a file storage with additional control functions.

See more examples: https://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments

@essenciary
Copy link
Member

essenciary commented Aug 3, 2023

As mentioned in #661 in Genie 6 (currently in the v6 branch) we have some support for this. It's not extensive as Rails' as it's greedy. So for now we only process routes like /foo/bar/* that would match /foo/bar/x, or /foo/bar/x/z etc.

The matching part ends up in params["_"] as x or x/z.

@essenciary
Copy link
Member

If you want to help with this for ex by extending it to match better (less greedy) and/or backport it to Genie 5, happy to help.

@rssdev10
Copy link
Author

rssdev10 commented Aug 4, 2023

Thanks, this is really good that you implemented this function. At the same time, RoR is still a good sample of how to organize dynamic components of the path. The cases 'books/*section/:title' or '*a/foo/*b' are also sometimes useful. E.g. for the 'books/*section/:title'I can manage a hierarchical taxonomy of sections and request the book by title. In case of '*a/foo/*b' the a can encode the API version, but b be a name of the resource. But no way to have more than one wildcard segment when using '_' variables.

BTW, have you thought about replacing of the for r in routes() with multiple regex checks by a single state machine implemented with something like Automa.jl to avoid performance problems in applications with many paths?

@essenciary essenciary changed the title wild-carded segments in a path Improvements to wild-carded segments in a path Sep 7, 2023
@essenciary
Copy link
Member

@rssdev10 I have not thought about replacing the routes lookup and your suggestion is very interesting. I'll look into it, thanks.

@essenciary essenciary self-assigned this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants