Datasheet

Even if you keep the same technology server side, you may decide to change the distribution of
the functions in the different scripts. For example, you may decide that you prefer to have a sin-
gle script for all the data sources with an additional parameter to specify the source, or you may
decide that you want three different scripts instead of one to get a watch, get a list of watches,
and save a watch. Again, these implementation choices shouldn’t have an impact on your users.
URLs are addresses for Web resources and using a single address with query parameters is like
having a care-of address in the real world; that method works, but it’s better to provide individ-
ual addresses to each resource.
To do so, you need to define the URL space that you’ll be using for BuzzWatch (as covered in Chapter 7)
and to implement it server side (as covered in Chapter 16). Designing a URL space includes, like any
design, a good deal of subjectivity. One rule of the thumb is to make a list of the different objects that
have their identifiers. BuzzWatch manipulates three different objects: watches identified by their names
(the current version uses stock symbols as names but that’s only a rather arbitrary implementation deci-
sion), companies identified by their stock symbols, and tags identified by tag names. A typical way of
defining a URL space for these three classes is to give them their own URL roots, such as:
http://web2
.0thebook.org/buzzwatch/watch/
, http://web2.0thebook.org/buzzwatch/company/, and
http://web2.0thebook.org/buzzwatch/tag/. These roots are then used to define a URL per object,
such as
http://web2.0thebook.org/buzzwatch/watch/wmt/, http://web2.0thebook.org/
buzzwatch/company/msft/
, or http://web2.0thebook.org/buzzwatch/tag/google/. The next
step is to use these URLs to define URLs per type of information. For a tag, we’d have
http://web2
.0thebook.org/buzzwatch/tag/google/delicious
for the del.icio.us and that would leave the
option of adding new resources for the same tag (for example, Technorati or Flickr search results). For a
company, you already have Yahoo! financial news, quotes, and charts and we could add more of them.
For a watch, you have the watch itself but need to differentiate the (X)HTML version from the XML
description and, eventually, the concatenated document with all the information for a watch.
Now that you have designed your URL space, how do you implement it? The good news is that if you
are using a Web server that supports URL rewriting, you won’t have to change a single line in your PHP
scripts. With Apache, for example, you would implement a URL space similar to what we’ve described
above with the following directives in a
.htaccess file:
..hhttaacccceessss
RewriteEngine on
RewriteBase /buzzwatch/
RewriteRule ^$ watch/welcome+page/ [R]
RewriteRule ^watch/welcome+page/$ index.php [L]
RewriteRule ^watch/([^/.]*)/$ index.php?name=$1 [L]
RewriteRule ^watch/list.xml$ watch.php [L]
RewriteRule ^watch/([^/.]*)/index.xml$ index.php?name=$1&format=xml [L]
RewriteRule ^watch/([^/.]*)/watch.xml$ watch.php?name=$1 [L]
RewriteRule ^tag/([^/.]*)/delicious.xml$ delicious.php?tag=$1 [L]
RewriteRule ^company/([^/.]*)/yahoo/finance/news.xml$ yahoo_finance_news.php?tag=$1
[L]
RewriteRule ^company/([^/.]*)/yahoo/finance/quotes.xml$ yahoo_quotes.php?tag=$1 [L]
RewriteRule ^company/([^/.]*)/yahoo/finance/chart.png$ yahoo_chart.php?tag=$1 [L]
RewriteCond %{THE_REQUEST} ^.*.php\??.*$
RewriteRule ^.*.php$ nophp [G]
34
Chapter 1
04_087889 ch01.qxp 5/2/07 12:56 PM Page 34