Datasheet
Regular expressions are a very powerful tool, and there’s much more to them than can be covered in a
brief introduction such as this. You’ll be using them in various places in this book, often within PHP. The
PHP web site has a handy description of regular expression pattern syntax at
http://www.php.net/
manual/en/reference.pcre.pattern.syntax.php
.
REST
REST, or Representational State Transfer, is a term that is often misused. Strictly speaking, REST describes
an architectural approach to building software systems. The term REST was first used by Roy Fielding,
one of the principal authors of the HTTP specification, in his PhD dissertation: “Representational State
Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of
web pages (a virtual state-machine), where the user progresses through an application by selecting links
(state transitions), resulting in the next page (representing the next state of the application) being trans-
ferred to the user and rendered for their use.”
A web application built on REST principles would model each object stored in the system as a unique
URL. So, a bookstore might use URLs of the following form:
http://www.somebookstore.com/books/0470097744
Here, 0470097744 is the ISBN of the book in question. When the URL is accessed, a document repre-
senting the book is returned— on the web, this is most likely an HTML page. Of course, there isn’t really
a different HTML page for every single book in the store— the pages are all dynamically generated
based on the information passed in the URL.
The HTML page for the book might include a link to a list of reviews of the book:
http://www.somebookstore.com/books/0470097744/reviews
Each review would also have its own URL:
http://www.somebookstore.com/books/0470097744/reviews/1
Each time the user follows a link to new URL, the new URL contains all of the context required to service
the request— there is no state required to be stored on the server; it is stored entirely in the URL. This is
a key feature of a REST system.
In the Web 2.0 world, the term REST is also often used to refer to any simple HTTP interface that exchanges
information (usually XML) without the aid of an additional messaging layer such as SOAP (see the follow-
ing section). The Flickr API has such a REST interface, which is covered in detail in Chapter 4.
REST interfaces such as the one offered by Flickr are URL-based, and represent a very concise way of
sending a request to the remote system. A typical REST request URL might look something like this:
http://www.flickr.com/services/rest/?method=flickr.photos.search
&user_id=50317659@N00&per_page=6&api_key=1f2811827f3284b3aa12f7bbb7792b8d
This URL performs a search for a user’s recent photos on Flickr. Don’t worry about the details of what
all those parameters mean right now — we’ll look at this request in more detail in Chapter 4. You can
19
Chapter 1: Rewriting the Web
05_097748 ch01.qxp 12/14/06 5:53 PM Page 19