[cgiapp] C::A::P::Routes
Michael Peters
mpeters at plusthree.com
Thu Mar 4 10:45:39 EST 2010
On 03/04/2010 10:04 AM, Brad Van Sickle wrote:
> Maybe CGI::Application::Dispatch or CAP::Routes is a better/more
> powerful way to do this... but I don't see how. Which is why I'm asking.
There are pros and cons to both ways (using mod_rewrite or Dispatch) and
I frequently use them both, even in the same project.
The main reasons I like (and wrote) Dispatch is because I wanted pretty
URLs with more meaning (REST-ish). This makes things slightly more sane.
But by doing it all in the proxy with mod_rewrite means that you need to
change your httpd.conf every time you change your application. If these
rules are in a proxy then it's definitely a violation of concerns when
your proxy server needs to be intimately familiar with your applications
URL structure. It also makes it harder to move the application around to
a different server setup or different proxy software.
And using Dispatch makes certain things way easier than mod_rewrite. Off
the top of my head:
+ Dispatching based on HTTP request type (GET vs POST)
+ Dispatching based on
+ Easier to understand and write. Compare
'/app/:rm/:year/:month/:day'
vs
RewriteRule /app/([^/]+)/([0-9]+)/([0-9]+)/([0-9]+)
http://server/app.pl?rm=$1&year=$2&month=$3&day=$4 [P,L]
Now try to imagine how much crazier that regular expression needs to
be if you wanted to do something like this:
'/app/:rm/:year?/:month?/:day?'
+ Easy to pass different parameters to your application's new() method.
Imagine for example a situation where you have a single application
(same code) but you need to customize that application depending on
the URL that was accessed. Maybe it's a beta version, or a different
client, etc.
--
Michael Peters
Plus Three, LP
More information about the cgiapp
mailing list