REST-compatible Ajax Patterns
Wednesday, 6 June 2007
Can AJAX be used to strengthen REST-style programming? Yes! Here are some common scenarios where AJAX is better than standard HTML.
User authentication
Display authentication dialog on the URL where access is attempted, instead of redirecting to a logon screen, and then redirecting back.
Dialogs
Present dialogs using DHTML instead of popping up windows. URLs should be permanent if they are meant to be bookmarkable. Dialogs are temporal, and have no need for URLs.
ASP.net or JSF backbutton
The curse of the backbutton goes away when ajax is used with ASP.net or JSF applications. Instead of building up a history list of POSTs to the same page, back button works again, and brings user to the previous screen. (Note: 10 June 2007 - Turning on SmartNavigation in ASP.net has the same effect, through using an IFrame to postback.)
Wizards (Guided User Interaction)
Since wizards encapsulate actions within a single dialog, an Ajax implementation can progressively gather data until user finally commits the transaction.
Refreshing Value-Observer Pattern
This is part of the pop-up window problem. When a pop-up window mutates state, the parent window may need to refresh. Although this is possible via javascript, there is an element of cooperation that is required between the pop-up window and the originating window. This can limit reuse. This leads to an interesting question: what I like about simple URLs is that you can reuse and bookmark resources. What I don’t like about URLs is they pretty much suck for modal interaction, or where gosub style navigation is involved. How do you approach these in your web apps?
I’m keen to hear from you if there are more cases when you think Ajax is appropriate. Let me know!