Skip to content

Update to hxNode

January 22, 2010

Updated API for node .js 0.125 and fixed some inconsistencies also addedServlet.hx which demonstrates the use of Node Http, and can be used like this …

 public static function
  makeGetUsersServlet() {
    var users = new JSONP(GETUSERS,function(req:IRequest,res:String->Void) {
        var
        session = field(req.validated,SESSID),
        page = Std.parseInt(field(req.params,PAGE)),
        rows = Std.parseInt(field(req.params,ROWS));

        if (Accounts.roleTrumps(MANAGER,session.role)) {
          Accounts.usersByPage(page,rows).addCallback(function(users) {
            res(reply(OK,{users:users}));
            });
        } else {
          res(reply(PERMISSIONS));
        }
      });
    users.required([SESSID,PAGE,ROWS]);
    users.validate(SESSID,NO_SESSION,Accounts.validateSession);
  }

create your servlets then fire up the server, e.g.

new HttpServer(accountServer.host,accountServer.port,”Accounts 0.1″);

I like to use lots of enums for param and servlet names so i can guarantee i get the spelling right in client haxe too,
this may not be to everyone’s taste – the nice thing is it’s small and easy to change.

Advertisements

From → haxe, javascript, node.js

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: