I'm developing a new application and I'm trying to come up with a convention for defining routes. Ideally, I would like it to be simple, flexible, and reversible.
Here are some from popular frameworks:
Backbone
route matches
-----------------------------------------------------
help help
search/:query search/kiwis
search/:query/p:page search/kiwis/p7
file/*path file/nested/folder/file.txt
docs/:section(/:subsection) docs/faq, docs/faq/installing
Django
Uses regexes, but comes with a complex regex reverser
route matches
-------------------------------------------------------------------------------------
^articles/2003/$ /articles/2003/
^articles/(\d{4})/(\d{2})/$ /articles/2005/03/
^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$ /articles/2003/03/03/
Ruby on Rails
:controller/:action/:id/with_user/:user_id
books/*section/:title
ASP.NET / MVC 5
{controller}/{action}/{id} /Products/show/beverages
{resource}.axd/{*pathInfo} /WebResource.axd?d=...
{productId:int}/{productTitle} /5/asp-net-mvc
books/{isbn?} /books, /books/1430210079
Django's is probably the most flexible, and it's already familiar to people that know regexes, but it's also the most difficult to read and reverse.
Backbone, RoR and ASP.NET all allow optional and wildcard/splat parts, with various syntaxes. MVC 5 has some options for restricting the parameters inline ala :int
.
Where might these schemes fall short, and how could they be fixed?