What about a something other than a string? I don't know the
current syntax or use cases well, so this suggestion may not make
sense, but what about a vector of things instead of /'s in
a string? This would let you leverage different literal types,
nice #"" regex escapting, etc:
[:account #".*", "product", :id #"\d+"]
Hm, that looks more cluttered than I was hoping. Maybe more like
destructuring a regex result would be better:
[account id] #"(.*)/product/(\d*)"
Well, just a couple ideas that came to mind.
--chouser
I dunno, I kinda think there doesn't seem to be much difference
between
(foobar))
(GET "/{account}/product/{id}" {"id" id-matches?}
And
(GET "/{account}/product/{id}"
(if (id-matches? (params :id)) (foobar))
I'm not sure I'm really convinced that a route should contain
arbitrary complexity, though I guess I can see it's advantage.
Kinda suggests to me that the groups should be put into local vars,
rather than in (params :account) and (params :id). I wonder if the
parameters in the route should be treated differently to the
parameters in a form or in the query string.
(GET #"/(.+)/product/(\d+)" [:account :id] ...)
For example, what if I want to support
"/tags/keyboard/peripheral/input-device" where the number and order of
tags is variable?
I could implement this as:
(map second (re-seq #"(?!/tags/)/([-\w]+)"
"/tags/keyboard/peripheral/input-device"))
which returns a seq of my tags
("keyboard" "peripheral" "input-device")
The problem I have with the current routes regex support is that it's
bound to re-matches, which only supports hard-coded groupings:
"/tags/(\w+)/(\w+)/(?#...forever..)" which doesn't work when you don't
know how many groups you might have.
There are still times when you want re-matches w/groups for
readability, but I'd like to at least have the option of capturing
these (unknown n) successive matches.
Rob
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "Compojure" group.
> To post to this group, send email to comp...@googlegroups.com
> To unsubscribe from this group, send email to compojure+...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/compojure?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>
(GET "/tags/*"
(show-tags (.split (:* (:route-params request)) "/")))
which is currently supported, is more readable than my hypothetical
re-seq version:
(GET #"(?!/tags/)/([-\w]+)"
(show-tags (:route-params request)))
While the second version would remain more concise, I'm not sure it's worth it.
Rob
Chiming in late but I experimented with non-string routes (see
http://moustache.cgrand.net/syntax.html#route) a while ago.
With Moustache the "/tags/*" route would be ["tags" & tags].
(The whole ring application would be (app ["tags" & tags] {:get (show-
tags tags)})).
James's example "/{account}/product/{id:\\d+}" would be [account
"product" [id #"\d+"]]
Christophe
http://werkzeug.pocoo.org/documentation/dev/routing.html
"/<account>/product/<int:id>"
Its a nice DSL because <> is not allowed in urls.
Robin
On Dec 27 2009, 6:24 pm, Robert Campbell <rrc...@gmail.com> wrote:
> What about adding re-seq support?
>
> For example, what if I want to support
> "/tags/keyboard/peripheral/input-device" where the number and order of
> tags is variable?
>
> I could implement this as:
>
> (map second (re-seq #"(?!/tags/)/([-\w]+)"
> "/tags/keyboard/peripheral/input-device"))
>
> which returns a seq of my tags
>
> ("keyboard" "peripheral" "input-device")
>
> The problem I have with the current routes regex support is that it's
> bound to re-matches, which only supports hard-coded groupings:
> "/tags/(\w+)/(\w+)/(?#...forever..)" which doesn't work when you don't
> know how many groups you might have.
>
> There are still times when you want re-matches w/groups for
> readability, but I'd like to at least have the option of capturing
> these (unknown n) successive matches.
>
> Rob
>
> On Tue, Oct 20, 2009 at 8:47 PM, James Reeves
>