Question

What is the purpose of manual web routing? Why doesn't everyone just automatically map between URLs and module/method/function names?

I would argue that you can start with fully automatic mapping, and then you can just use Apache mod_rewrite or mod_redirect or whatever if you want to refactor in a way that would change URLs, without breaking existing URLs.

Was it helpful?

Solution

There are two main reasons for using manual routing, over automatic.

  1. Manual routing allows you to use REST as it is meant to be used. This means that the same URL can access 4 different actions, distinguished by the HTTP method used (POST, GET, PUT, DELETE). With automatic routing, you would be exposing the method names of your underlying functions, therefore, you would have 4 different URLs.

  2. Manual routing also allows you to produce more search-engine friendly URLs. This is usually achieved using the slugify method, but the manual routing allows you to ignore this extra information, and just concentrate on the ID part of the URL to correctly route you to the specific resource.

Another reason, which is purely cosmetic, is that the URLs just look better. Does that matter? Some may think so.

OTHER TIPS

One argument you could make is that the URL namespace your application presents is part of its user interface and therefore the routing rules that govern it belong with the rest of the application's source code. Also, in the case of Ruby on Rails, the routing configuration is all just Ruby code, so you can have more complex business logic in there if required than Apache modules alone would allow.

For restful HTTP the URL are important. So if you only use automatic URLs you have a lot of not so nice URLs. For example you can use the same URL /udpateUsers for Users.edit() and User.save() in Play by differencing between GET and POST. Furthermore you can support data-binding like /users/show/1 to show the User with id 1. However the default in Play is to do it automatic.

What is a "module" in a generic web sense?

Apache's default is to map to a filesystem, because that's one of the only things that that all systems running Apache have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top