views:

149

answers:

2

I am looking at implementing URLMapping for a personal project. I am already aware that solutions exist so please do not answer suggesting I should use one.

What I want is to harvest the opinions of fellow developers and web users on URL mapping implementations. Specially I would like you to answer:

  • Which is your favourite implementation?
  • What do you like about your favourite implementation?
  • What do you not like about your favourite implementation?
  • How would you improve it?

I would like you to answer from two points of view:

  • As a developer
  • As a user

I would be grateful for any opinions on this matter, thanks!

+1  A: 

Well, I should have noticed the url-routing tag shouldn't I? :-) Sorry about that.

jcd's experience mimics mine - Django is what I use too.

I like the fact that the routes for an app reside within the app (in urls.py) and can just be included into any projects that might make use of that app. I am comfortable with regular expressions, so having the routes be specified in regex doesn't phase me (but I've seen other programmers scratch their heads at some more uncommon expressions).

Being able to reverse a route via some identifier (in Django's case by route's name) is a must. Hardcoding urls in templates or controllers (view in Django) is a big no-no. Django has a template tag that uses the reverse() method

The one thing I wish I could do is have the concept of default routes in django (like Rails does or even Pylons). In Django every route has to map to a view method, there is no concept of trying to call a certain view based on the URL itself. The benefit is that there are no surprises - your urls.py is the Table of Contents for your project or app. The disadvantage is that urls.py tend to be longer.

celopes
hmm, default routes would be pretty easy to add, i think. just add a catchall regex at the end of a urlpatterns block that goes to a view function. the view function uses some python introspection to look at the available methods and delegates to a matching one.
lawrence
+1  A: 

I've only worked with django's URLConf mechanism. I think the way it relies on the urlpatterns variable is a bit flimsy, but I like its expressiveness in specifying patterns and dispatching to other url configurations. I think probably the best thing is to figure out your URL scheme first, and then try out a couple of solutions to see what matches best. If you're going hard-core REST using the full complement of GET/POST/PUT/DELETE, and checking the user agent's Accept headers, and all that, django will, by default, have you splitting your logic between URL config files and view files, so it might not be the cleanest solution.

However, since it's all Python, you might be able to do some more complex processing before you assign to urlpatterns.

Really, you want a system that does what you need. Your URL scheme is your API, so don't compromise on it based on the tools you use. Figure out your API, then find the tools that will let you do that and get out of your way.

Edit: Also do a google search for "URL scheme design." I found this without much effort: http://www.gaffneyware.com/urldesign.htm. Not comprehensive, but some good advice gotten from looking at what flickr does.

jcdyer