February 1, 2011

Delphi Relax: Architecture and Strategy

Delphi Relax is an extension of Delphi XE DataSnap REST Application architecture, with a particular focus on supporting jQuery for the browser user interface.

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!

 





 

9 Comments

Delphi Relax Architecture and Strategy 

Marco --

Sorry if I missed this...

What is the nature of the project?  Will it be open 
source, or will you manage it all and  make it 
available?  Will it be hosted via GoogleCode, 
SourceForge, etc?

Nick 
Comment by Nick Hodges [http://www.nickhodges.com] on February 1, 17:38

Delphi Relax Architecture and Strategy 

Nick--

my bad, I took this for granted. It will be an open 
source project, with a flexible license like MPL. I plan 
hosting it on code.marcocantu.com, using a SVN 
repository, got a few GB on it... in fact, it is already 
there, but empty.
Comment by Marco Cantu [http://www.marcocantu.com] on February 1, 17:43

Delphi Relax Architecture and Strategy 

Nick--

my bad, I took this for granted. It will be an open 
source project, with a flexible license like MPL. I plan 
hosting it on code.marcocantu.com, using a SVN 
repository, got a few GB on it... in fact, it is already 
there, but empty.
Comment by Marco Cantu [http://www.marcocantu.com] on February 1, 17:43

Delphi Relax Architecture and Strategy 

Relax is also the "motto" of couchDB, a noSQL database
(see http://couchdb.apache.org/ ): "CouchDB provides a
RESTful JSON API than can be accessed from any
environment that allows HTTP requests."

Marco, Delphi is great to develop GUI Native
Applications; a noSQL dbExpress driver would be useful
and help Delphi to stay in touch with database
evolution, but nowadays WEB development flourishes in
other ecosystems (PHP, RoR) IMHO.

Thanks for your generous efforts, anyway; as a
seasoned delphist I really appreciate.

CIAO !
Comment by Angelo Biolcati Rinaldi [http://about.me/biol] on February 1, 19:34

Delphi Relax Architecture and Strategy 

Hi Marco,

> "For public pages, though, the AJAX + REST model has
a big drawback: very limited indexing by search engines!"

Google recently started promoting a way of crawling
AJAX-enabled websites.  From memory, the URL should
change to include an anchor and exclamation mark
followied by key/value pairs - ie,
blah.html#!/ajaxkey=ajaxvalue .

You can read about it here:
http://code.google.com/web/ajaxcrawling/docs/getting-started.html

I don't do any web programming or use REST so I have
no idea if this will be useful to you, but I hope so!

Cheers,

David
Comment by David M [] on February 1, 23:36

Delphi Relax Architecture and Strategy 

Wow... Excellent news.

Can wait to see this in the SVN repository..!

I was thinking of a Razor extension for WebBroker
myself...!!

Any early drafts of your 'razor' / 'shaver' / 'blade'
appearing in the repository soon ??

Thanks again

Andrew

Comment by Andrew Tierney [http://www.castlesoft.com.au] on February 2, 02:45

Delphi Relax Architecture and Strategy 

 Greetings Marco,

Your webinar last week was great!

There are some really interesting ideas here.

Do you think using JQ Grid would work with this
architecture?  JQ Grid does its own AJAX.  So I would
think this would conflict with the DataSnap AJAX.

But I don't know for sure.

Thanks Marco.

Keith
Comment by Keith on February 2, 04:12

Delphi Relax Architecture and Strategy 

Couch DB has decided afik against a driver model. 
Mongo DB did decide for one.
Comment by Michael Thuma on February 3, 22:48

Delphi Relax Architecture and Strategy 

Hi Marco, 

Thanks for your work, it's much appreciated. 

I have noticed a possible spelling error: 

First Steps
As I mentioned I hope to start getting come ??(some) ?? 
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. 
Comment by Andre Jansen [http://www.compunet.co.za] on February 23, 07:28


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.