mercoledì 1 agosto 2007

An HttpView2 Canvas sample

Here's a quick example on how to use the new Canvas system of HV2.

First of all, create an new TestView class as a subclass of HVTransientView:
HVTransientView subclass: #TestView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Test'

Then, create a default method as follows:
| canvas |
canvas := self canvas.
canvas html:
[canvas head: [canvas title text: 'Test!'].
canvas body:
[canvas h1 text: 'A test of HV2''s new Canvas system'.
canvas p text: 'This is a simple test of the latest HV2 version']].
^ canvas

To start the engine, type the following on a Workspace then DoIt:
TestView startOn: 8080.

As soon as the HV2 engine has started, you can point your browser to http://localhost:8080/. Here's a screenshot of what you'll see:HV2's new canvas system.

You should also note that you can omit the ^ canvas expression in the default method. If you do so, HV2 will retrieve the response from the TestView instance itself.

HttpView2 status report

In the past days, I've continued working on HttpView2.

I've completed support for XHTML 1.1 in class HVXHTMLCanvas . I've also extracted from HVXHTMLCanvas an HVCanvas class that provides support for generic XML documents.

On the other hand, I've decided to scrap the current HVPainter system and punt the new one to the next release of HV2.

The other big change from HV2's current stable release is related to the HTTP response. In the stable release (1.0x), the HTTP response is automatically created from the builder and the user has no control over it. In the current development release, the HttpResponse object has been exposed in the HVTransientView class. The various URL methods may access it, modify the status code, the content type and the contents itself.

With these modifications, HV2 may be used (albeit awkwardly) as a simple engine for RESTful web services.

As soon as Goran, HV2's mantainer, gets back from his vacations we'll publish the new development version on the SqueakMap. Meanwhile, you may find the code on the Monticello repository as version HV-gc.132.