Delphi Relax is an extension of Delphi XE DataSnap REST Application architecture, with a particular focus on supporting jQuery for the browser user interface. I've already mentioned this project  in my webinar last week and in the blog. Now, I'd like to start introducing it, at least mentioning the key elements of its architecture. Some code might start to become available soon...

Relax...

First, the project name " Delphi Relax " stands (vaguely) for Delphi REst LAyer eXtension. Relax is a word close the term rest (of course not in technical terms) and used in other languages beside English (Italian, for example). It is quite international. The only IT project with this name is a rather obscure regular expression engine for XML. So, I've gone for it (and thanks for the suggestions).

The Goal

The goal is to extend (not replace!) Delphi's WebBroker and DataSnap REST Application architecture, as found in Delphi XE. Whenever possible, I'm trying to use what's in the system, and augment it, providing alternative solutions, but avoiding to overlap with existing code. In some areas, however, the solution is too weak or not appropriate for my goal and I replaced it. The project started with a client (who's very active on it) and I'm rebuilding a couple of my sites as an experiment.

If you don't know much about Delphi's DataSnap REST Application architecture, here I don't want to repeat any of it, just refer to my free 60-pages white paper on Embarcadero web site for information. So what do I plan adding to the core structure?

1. Razor Clone

By default, Delphi uses PageProducer components to customie the HTML returned by the server. This is way too limited, and hasn't even got a clean way to have a shared template for the web site pages. Also, the tag-based notation (<#custom attrib="value">) is not very easy. Looking around, I found the Razor engine for ASP.NET, currently under development by Microsoft, quite nice. So the previous tag will become @custom.value. The current aim is to have a minimum of data access, loops, conditional statements, and a way to merge a template with given page. And a light translation support.

This is not the core of the project though, because for editing and also for viewing data the model is to have a skeleton HTML page and make a REST call to fetch the data. This will remain (in my idea) the only way to access password-protected and user information. For public pages, though, the AJAX + REST model has a big drawback: very limited indexing by search engines! And some flexibility in generating the pages is useful anyway.

2. Extended session and users management features

Sessions are managed in the DataSnap REST servers and they work fine, even if they are bound only to the REST calls, not the HTML generation, but this is fine. Authentication, however, is an all-or-nothing business. If you ask for authentication, you basically need it for any operation. So if you want to allow a non-logged user to perform editing actions and work on the site, it is hard to use the current mechanism. But it is also quite easy to extend. Make any used a logged user, called guest, and you are up and running. You can then rely on the TAuthRole mechanism to protect individual REST calls from specific groups of users.

There are also some extensions to session data storage, but quite simple.

3. ActiveRecord 

How to you send an object to the JavaScript user interface? By transforming it into a JSON representation. But how to you get an object in the first pace, if your data lives in a database. Like in many other "thin" object layers, I'm using a very bare bone (for now) ActiveRecord structure with direct mapping of properties to database table fields. This area might grow, but I don't think a full ORM layer will be appropriate, also because these in-memory objects are not kept around between invocation, with limited exceptions. Some limited customizations in the JSON and database mapping are available via, you can guess, custom attributes.

4. Supporting jQuery

One of the core areas is the ability to generate JavaScript code, or more precisely jQuery code, from the Delphi server. JavaScript is just some text, after all. This is introduced at the end of the white paper, so you can get an idea of the model. This code is used for mapping objects to the user interface (as in the white paper), but also for validating input, creating lookups, and more. This area is heavily based on custom attributes you can use to decorate the Delphi object to obtain a specific behavior... in the browser! Validation is performed also on the server with the same client-side rules, though, to avoid accepting illegal data in case of a direct REST call.

5. And more

There are other areas in the work, and probably more than could be added in the future. So don't take this as a complete list.

First Steps

As I mentioned I hope to start getting come code out very soon, probably starting with the Razor clone (for which I might use a different name, as Microsoft might not like it), which should be usable in a generic WebBroker application, with no DataSnap REST involved. The rest of the code is still a little intertwined with the projects it is used in, hope I'll be able to clean it up soon. And I'll also need time to get some documentation out there... Not sure when I'll find the time. I'll welcome help, but only as the project becomes a little more stable. I plan hosting Q&A sessions, maybe using a chat interface. 

But I really think Delphi deserves an alternative web development model and this is quite an interesting one. You'll need to have Delphi XE Enterprise to use the complete set of features, but the good news is you can find it discounted from today and until the end of March. There is also a very cheap upgrade from Delphi XE Professional!