mark nottingham

Putting the Web back in Web 2.0

Monday, 14 August 2006

HTTP

Timbl has this great term “ Webizing” that he uses to talk about giving existing systems the benefits of the Web architecture. Despite the first part of “Web 2.0”, I think AJAX is in severe need of some serious Webizing.

Case in point, script.aculo.us has a great autocomplete function, but it uses POST by default. What’s up with that? GET will do just fine, and gives you caching for free.

Furthermore, it forces you into using query strings (e.g., http://example.com/suggest?q=AAPL), which means it’s difficult to serve results from plain files with many Web servers. After all, if you’re auto-suggesting things like stock tickers, it’s not like you need to do a database query for every one; a filesystem is perfectly servicable, and ever-so-more performant.

Luckily, both are trivial to fix.

The request method can be set via the ‘method’ item in the options argument (although you’ll need to lowercase it, thanks to prototype’s craziness). E.g.,

new Ajax.Autocompleter("suggest", "suggest_choices", "/suggest", {method: 'get'})

Don’t forget to set your caching metadata!

Allowing more flexible URIs requires a bit of modification, but script.aculo.us is nothing if not extensible.

Http.Autocompleter is a quick and dirty modification of Ajax.Autocompleter that a) uses GET by default, and b) takes a URI template as an argument, instead of a URI. That template has one variable, “query”. E.g.,

new Http.Autocompleter("suggest", "suggest_choices", "/suggest/{query}")

Of course, you can also use templates like /{query}, /suggest?q={query}, /suggest;{query} or even /suggest/{query}/JSON.

How much more easy to use and flexible is that? Don’t let tools tell you how to form your URIs, and certainly don’t let them force you to serve your content in a particular way.


2 Comments

Stefan Eissing said:

I am all for Webizing and Webifying. I currently have to interface some web services in a project and, boy, it ain’t pretty.

And a lot of the problems are POST related. GET would work much better, but it’s not the default and people dont really understand the differences. So Webizing efforts: Go!

Tuesday, August 15 2006 at 9:49 AM

john said:

Great work

Wednesday, August 23 2006 at 5:36 AM