Thursday, July 9, 2009

HTML 5, HTTP Methods & REST

See HTML 5, HTTP Methods & REST at its new home on

Lots of very exciting things are happening right now for us web standards aficionados. The big news is the buzz around HTML 5 and its growing support in modern web browsers (modern meaning not Internet Explorer). The current state of web standards makes it difficult, but certainly not impossible, to use the web as a true application platform. HTML 5 promises to change this (maybe not fully until 2022 — but we're patient). Many articles have been written about HTML 5 but there's one tiny, but very important, feature I'd like to focus on here: support for the HTTP PUT and DELETE methods in forms. First, a little bit about REST…

I've talked about REST here before but REST is useful for more than just building web services. REST is an abbreviation for representational state transfer and is an architectural style for building software. The web itself is built using REST so it is a proven and scalable architecture. Unfortunately many web developers ignore REST to their detriment. Conforming to REST principles can help with search engine optimization (SEO) as well as make your web applications more usable (through predictability of actions) and scalable (the web itself has scaled to massive proportions).

Using a RESTful approach, every URL is a representation of a resource (a noun). These resources can then be retrieved and manipulated (have their state changed) using a standard set of verbs. These verbs are actually HTTP methods. There are a whole bunch of verbs/HTTP methods but only worry about four of them (at least for now): GET, POST, PUT, and DELETE. Here is an example of how some nouns and verbs can be used to together, borrowing from the Atom Publishing Protocol (APP):

HTTP methodURIresult
GETs a collection of people
POSTs a new person to the collection (using data in the POST request)
GETs bradley-holt
PUTs an updated version of bradley-holt (using data in the PUT request)
DELETEs bradley-holt

The problem was that up until now there was no way to specify a form method other than GET or POST. This meant that everything had to be tunneled through POST (or had to be done using JavaScript) which, while not technically incorrect, was incovenient and did not allow web developers to fully express the intent of user actions. HTML 5 specifies that forms can now have the methods of PUT and DELETE as well. This simple addition is one small way in which HTML 5 will allow the web to become more of a fully-feature application platform.

For you Zend Framework developers: I just learned today that Zend Framework 1.9 will include a new REST router which will help web developers adhere to RESTful principles. Please use it and also use the new PUT and DELETE methods in HTML 5 forms as browser support catches on.


mweierophinney said...

Part of the REST offering we're providing in ZF 1.9 is a PutHandler plugin, which allows you to retrieve PUT data just as you would POST data via the request object. For instance, if your PUT body contained "foo=bar", you could grab it with $this->_getParam('foo') in your action controller, or directly as a request parameter ($request->getParam('foo')). This makes support for PUT requests first-class within ZF -- something I'm particularly excited about.

Bradley said...

@mweierophinney That's great to hear! Between HTML 5 and these new ZF 1.9 features, I feel like a kid at Christmas :-)