## getting started
```javascript
//----------------------------------------------
// file: program.ts
//----------------------------------------------
export module services {
// url: http://localhost:3000/services/message
export function message (context) {
context.response.write('hello typescript');
context.response.end();
}
}
//----------------------------------------------
// file: app.js
//----------------------------------------------
var appex = require('appex');
var runtime = appex.runtime ({ source : './program.ts', devmode : true });
require('http').createServer( runtime ).listen(3000);
<a name="getting_started_on_express" />
## getting started on express
```javascript
//----------------------------------------------
// file: program.ts
//----------------------------------------------
export module services {
// url: http://localhost:3000/services/message
export function message (context) {
context.response.write('hello typescript');
context.response.end();
}
}
//----------------------------------------------
// file: app.js
//----------------------------------------------
var express = require('express');
var appex = require('appex');
var app = express();
app.use( appex.runtime( { source:'./program.ts', devmode:true } ) );
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
## developing with appex
To enable development mode, set the devmode option to true on the runtime option parameter.
var runtime = appex.runtime ({ source : './program.ts', devmode : true });
Appex is built directly on top of the Microsoft TypeScript 0.9 compiler and leverages it for tight
integration with the nodejs platform. By enabling the 'devmode' option will have the compiler
effiecently rebuild typescript source code on each request made to the server.
Appex achieves performance in this regard by leveraging features introduced in
TS 0.9 which allows incremental building / caching of typescript compilation units.
In addition to this, compilations are run in a background worker process to ensure they do interupt
requests being served on the web process.
The benefit to this is that updates can be made to source files without needing to restart the web process. Additionally,
syntactic errors made in typescript source code do not bring the web process. Everything stays running (excluding runtime
errors).
Appex will output detailed syntax and type errors on the main process stdout stream, as well as a http response.
### json handler function
A json handler is a function which will accept HTTP POST'ed json strings and
pass it to the function as a object. A json handler has three distinct arguments:
- arg0 - the http context which contains the http request and response.
- arg1 - the json request object
- arg2 - a typescript callback with a single argument for the object response.
The return type is optional. json handler functions "must" call the callback to
complete the request.
export function method(context:any, request:any, callback:(response:any) => void) : void {
callback(request);
}
### public and private functions
Appex extends TypeScripts concept of visibility to include visibility over http. From this
developers and control which functions are exported as http handlers.
Appex will create routes only for functions marked with export and for functions that reside
withing modules with export.
Consider the following example:
module private_module {
export function public_method () {
}
}
function private_function() {
}
export function public_function (context:any) {
private_function();
private_module.public_method();
}
which will result in a single route.
http:
## structuring projects
Appex leverages TypeScript's ability to reference source files with the element. Appex
will traverse each source files references and include it as part of the compilation.
Developers can use this functionality to logically split source files into reusable components of
functionality, as demonstrated below.
var appex = require('appex');
var runtime = appex.runtime ({ source : './index.ts', devmode : true });
require('http').createServer( runtime ).listen(3000);
export function index (context) { }
export function about (context) { }
export function contact (context) { }
export module users {
export function login (context) { }
export function logout (context) { }
}