RouteMatcher named path parameters with regex

1,238 views
Skip to first unread message

Ranie Jade Ramiso

unread,
Jun 26, 2013, 11:11:51 PM6/26/13
to ve...@googlegroups.com
Basically what I want is something like this:

 routeMatcher.get("/post/:id{[1-9][0-9]+}", ...)

It is exactly the same as named path parameters but a bit more restrictive. Matching only the id parameter if the regex inside the curly braces matches.

What is your opinion about this? I have started working on this in my local repo to support this.

Your input is much appreciated. :)

Tim Fox

unread,
Jun 27, 2013, 2:47:27 AM6/27/13
to ve...@googlegroups.com


On 27/06/13 04:11, Ranie Jade Ramiso wrote:
Basically what I want is something like this:

 routeMatcher.get("/post/:id{[1-9][0-9]+}", ...)

It is exactly the same as named path parameters but a bit more restrictive. 
Matching only the id parameter if the regex inside the curly braces matches.

What is your opinion about this?* *I have started working on this in my 
local repo to support this.

Your input is much appreciated. :)


Ranie Jade Ramiso

unread,
Jun 27, 2013, 3:04:13 AM6/27/13
to ve...@googlegroups.com
Yeah, but the captured groups are bounded to generic parameters names (e.g. paramn). Basically it just makes writing the route url much cleaner and easier to read :).

________________________________________________________________

Ranie Jade Ramiso <raniejaderamiso.com>
Software Engineer | Opensource Enthusiast | Professional Slacker 
___________________________________________________________________________


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tim Fox

unread,
Jun 27, 2013, 3:09:51 AM6/27/13
to ve...@googlegroups.com
Right, I think this is because Java regex doesn't support named
capturing groups.

On 27/06/13 08:04, Ranie Jade Ramiso wrote:
> Yeah, but the captured groups are bounded to generic parameters names (e.g.
> param*n*). Basically it just makes writing the route url much cleaner and
> easier to read :).
>
> *________________________________________________________________*
> *
> *
> *Ranie Jade Ramiso <raniejaderamiso.com>*
> *Software Engineer | Opensource Enthusiast | Professional Slacker *
> *Twitter <https://twitter.com/raniejade> |
> Facebook<http://www.facebook.com/72878331c221485527705ba87e511306>|
> Github <https://github.com/raniejade>*
> *___________________________________________________________________________
> *

Tim Fox

unread,
Jun 27, 2013, 3:10:58 AM6/27/13
to ve...@googlegroups.com
Ah, no. Named capture group support was added in Java 7 it appears.

Ranie Jade Ramiso

unread,
Jun 27, 2013, 3:15:54 AM6/27/13
to ve...@googlegroups.com
Yes, named captured groups are supported. The current route matcher however always binds the parameters to the generic ones.

________________________________________________________________

Ranie Jade Ramiso <raniejaderamiso.com>
Software Engineer | Opensource Enthusiast | Professional Slacker 
___________________________________________________________________________



For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

Yangming Huang

unread,
Dec 5, 2014, 5:59:06 PM12/5/14
to ve...@googlegroups.com
Hi, Tim, is there any updates on this?

Jose Antonio Illescas del Olmo

unread,
Jul 30, 2015, 2:05:50 AM7/30/15
to vert.x, timv...@gmail.com
Hi Tim, I'm new in vert.x community...

    This is an incredible feature, also you can add support for "." and "-" characters on placeholder names

I intend this...

  I have next URLs for address resource on my system:

     /addresses?customer.id={id}&accounts.id={id}
     /customers/{id}/addresses    =>    similar to    /addresses?customer.id={id}
     /accounts/{id}/addresses    =>    similar to    /addresses?accounts.id={id}

And y want only one handler to dispatch all request over "address" resource/subresource

   router.route("/customers/:customer.id/addresses").handler(ctx -> {
     ... (same handler than /addresses)
   });
   
   router.route("/account/:account.id/addresses").handler(ctx -> {
     ...  (same handler than /addresses)
   });
   
   router.route("/addresses").handler(ctx -> {
    ctx.response().putHeader("content-type", "text/html").end("/addresses?customer.id="+
                           ((ctx.request().getParam("customer.id")==null)?"":"?customer.id="+ctx.request().getParam("customer.id"))+
                           ((ctx.request().getParam("account.id")==null)?"":"&account.id="+ctx.request().getParam("account.id"));
   });

You can see that all URLs can processed by same unique handler...  (but currently only works for last route /address because placehoder name not allows "." and regexp capturing named-groups not works...)

I expect that you can appreciate this feedback to do vert.x "the best" asyncronous server of class
Thank You
Reply all
Reply to author
Forward
0 new messages