0

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.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • 1
    What exactly is the question? Where do you see "manual routing"? What's the difference between "manual routing" and mod_rewrite? – deceze Sep 02 '11 at 08:12
  • My claim is that you can start with automatic routing (0 lines of routing) and then add mod_rewrite (1 or 2 lines of routing, using regular expressions) later if necessary to deal with refactoring. Rather than create a manual route for every single exposed method/function (100s of lines of routing). – Robin Green Sep 02 '11 at 08:52
  • @Robin Green a claim is not a question. You should rephrase it as right now it's confusing what you want to say/ask. – Pere Villega Sep 02 '11 at 09:11
  • @Robin Yes, and nobody is saying any differently. :) Why isn't everybody doing this? Because... not everybody has realized this? Because... they have some legacy reason? Because... they were drunk when they coded their routing? Because... the sky is blue? – deceze Sep 02 '11 at 09:13

4 Answers4

5

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.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Codemwnci
  • 54,176
  • 10
  • 96
  • 129
2

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.

John Topley
  • 113,588
  • 46
  • 195
  • 237
1

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.

niels
  • 7,321
  • 2
  • 38
  • 58
0

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.

Gareth
  • 133,157
  • 36
  • 148
  • 157
  • Yes but it's not Apache's job to know about your programming language, so I was talking about using Apache to rewrite URLs. Just as an example of how you could do it. – Robin Green Nov 01 '11 at 16:44
  • My point was that Apache's default is to map to a filesystem, preciselly *because* Apache doesn't know about your programming language. How do you "start with fully automatic routing" if Apache doesn't know what your language is? Maybe I don't get what you mean by "automatic routing" – Gareth Nov 01 '11 at 17:24
  • I mean automatic routing provided by your web framework, which generates URLs for each method/function/etc. And e.g. in Play you can ask the framework to get the corresponding URL for the method you want to want to handle the next request. – Robin Green Nov 01 '11 at 18:10
  • Ok, then I'll have to back out of this question, because I don't know of any framework which offers automatic routing which *can't* do what you describe – Gareth Nov 01 '11 at 18:18
  • My question is not about "why are some frameworks like this" but "why are some developers who _use_ those frameworks like this" (although the former inevitably contributes to the latter). – Robin Green Nov 01 '11 at 20:18