Web Framework

A web framework consists in several tools that are helping you to create fast and secure web applications.

Target Platforms

Haxe currently compiles to different web-service oriented platforms :

  • PHP : Haxe compiles to PHP5 files that can be deployed on any web server / shared host configured to run php modules. There are no specific requirements for Haxe : simply deploy the generated .php files and you're done.
  • Neko : NekoVM is a lightweight VM with low memory usage and good performances (some tests show x30 speed against PHP). One of the nice feature of Neko is that its bytecode caching mechanism will also cache static values after they have been initialized : you can then have persistent data directly accessible in memory. Neko can be run into Apache web server by using mod_neko or with it's own application server called Tora.
  • C# and Java support is currently in progress

Database Engine

The main database engine for Haxe is included as part of the Haxe standard library and is called SPOD. The standard library also includes support for both MySQL and SQLLite, and a db interface layer that you can easily implement to support any other custom database (see Connection).

SPOD allows for class/table relationship, here's an example of a database table declared with SPOD :

import sys.db.Types;
class User extends sys.db.Object {
    public var id : SId;
    public var name : SString<50>;
    public var birthDate : SDate;
    public var email : STinyText;
    public var acceptEmail : SBool;
}

You can then create new user by doing the following :

var u = new User();
u.name = "Nicolas";
u.birthDate = Date.fromString("1979-08-28");
u.email = "ncannasse@.....com";
u.insert();

But the best part of SPOD is that you can request your database table by using simple Haxe code, here's a few query examples :

// get all users in the given range
User.manager.search($id > 10 && $id < 40);
// get users based on age
User.manager.search($birthDate > Date.fromString("2000-01-01"));
// search based on email host
User.manager.search($email.like("%@gmail.com"));

All these queries will be strictly typed and will generate at compilation time the corresponding SQL query.

You can learn more about SPOD by reading its own manual entry

Template Engine

When you want to print a web page result, you could include your html into your own source code, but that's quite ugly. You often want to separate your code logic from the actual presentation of it. But the presentation also requires a minimal set of scripting facilities such as conditionals, loops, calls and a few others.

There are several template engines available in Haxe, but the two mostly used are Templo and Erazor.

URL Dispatching

CSS Engine

External tutorials :

version #20018, modified 2014-03-15 00:39:29 by filt3rek