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

Allow regex in routes #1062

Closed
wants to merge 3 commits into from
Closed

Allow regex in routes #1062

wants to merge 3 commits into from

Conversation

smcmurray
Copy link

Adds regex routes as suggested in issue #1061.

@smcmurray
Copy link
Author

I know this is broken code. I'm hoping that somebody who knows D will understand the intent and fix it or replace it with better.

@s-ludwig
Copy link
Member

s-ludwig commented Apr 7, 2015

The problem is that while the implementation in the old naive router implementation is straightforward, implementing this for the new DFA based router is a lot more involved. Apart from that it doesn't mix with the wildcard support, so there would have to be something that tells regex based routes apart from normal ones.

Another possibility, which other frameworks offer, is to only support the regex for placeholder variables:

router.get("/items/:(var:[0-9]+)/something", ...);

It would then be implemented as step after the basic route matching.

@smcmurray
Copy link
Author

@s-ludwig As indicated in issue #1061, I don't have much to go on for how routes are supposed to work. I think I imitated the behavior that was in the code for wildcards, if by "wildcard" you mean "*". I don't know anything about a new DFA-based router. Is it documented somewhere?

I did note issues with "*" in the comments of the code. The Route constructor is overloaded to accept both a string and a regex.

router.get(regex(r"/items/(?P<var>[0-9]+)/something"), ...);

should work just fine.

@s-ludwig
Copy link
Member

s-ludwig commented Apr 7, 2015

Okay, using separate overloads would indeed avoid the issues in mixing the two approaches.

The DFA (erroneously called "tree" in the code, it's really a directed graph) is used by default instead of the linear Route probing: https://github.com/rejectedsoftware/vibe.d/blob/1908505af05154b172f97baca8624c2ff953cf60/source/vibe/http/router.d#L110

I'll fix the documentation later, but currently wildcards and placeholder variables are relatively limited (but useful enough for all usual needs):

  1. Wildcards may only be at the end of the match string and match any string: /some/path* for example matches /some/pathxyz or /some/path/asdasd)
  2. Placeholders must be at the end of the match string, or have to be followed by a slash: /foo/:placeholder/bar or /foo:placeholder are valid, but /foo/:placeholder1-:placeholder2 doesn't work.

@Geod24
Copy link
Contributor

Geod24 commented Apr 8, 2015

Le 7 avr. 2015 14:05, "Sönke Ludwig" [email protected] a écrit :

Another possibility, which other frameworks offer, is to only support the
regex for placeholder variables:

router.get("/items/:(var:[0-9]+)/something", ...);

It would then be implemented as step after the basic route matching.


Reply to this email directly or view it on GitHub.

The syntax will more likely be Python's named group, which std.regex
supports (-> "/items/:(?P[0-9]+)/something/").
That would indeed be very cool to have.

@s-ludwig
Copy link
Member

Closing this, since the implementation approach doesn't work anymore. I'll open a separate ticket instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants