<commit_before>![](https://raw.github.com/sinclairzx81/appex/master/assets/logo.jpg)

### develop nodejs web services with [typescript](http://www.typescriptlang.org/)

## install

```javascript
npm install appex
```

* [overview](#overview)
* [getting started](#getting_started)
	* [runtime](#runtime)
	* [options](#options)
	* [http server](#http_server)
	* [express server](#express_server)
* [developing with appex](#development_mode)
* [functions](#functions)
	* [http handler function](#http_handler_function)
	* [json handler function](#json_handler_function)
	* [public and private functions](#public_private_functions)
	* [the index function](#the_index_function)	
	* [routing with modules and functions](#function_routing)
* [structuring projects](#structuring_projects)
* [typescript resources](#resources)

<a name="overview" />
## overview

Appex is a nodejs web service framework built on top of the TypeScript programming language. Appex 
enables nodejs developers to expose typescript functions as http endpoints as well as generate meaningful service
meta data for clients to consume.

Appex also provides a dynamic compilation environment for typescript to aid in development. Appex will effeciently 
manage compilation in the background without the need to restart the web server, or use addition modules.

Appex is designed to operate as both a standalone web service solution or a compliment an existing applications written
in frameworks such as express / connect.

Appex makes writing http endpoints as easy as writing a functions. 

<a name="getting_started" />
## getting started

The following outlines setting the Appex runtime. 

<a name="runtime" />
### runtime

The Appex runtime is compilation engine that handles compiling typescript code, mapping routes to functions and 
invocation. Appex provides a utility method to setting for setting up the runtime, as described below.

```javascript
var http    = require('http');

var appex   = require('appex');

var runtime = appex.runtime ( { sourcefile : './program.ts' } );

var server  = http.createServer( runtime );

server.listen(3000);
```

The appex.runtime() method returns a http handler function which is both compatable with nodejs' 
http server as well as connect middleware. This is the recommended means of creating runtimes, 
However, if you need to access the runtime directly or are simply curious, you can also setup 
the runtime in the following way...

```javascript
var http    = require('http');

var appex   = require('appex');

var runtime = new appex.Runtime ( { sourcefile : './program.ts' } );

var server  = http.createServer( function(req, res) {
    
	console.log(runtime); // investigate the runtime.

    runtime.request_handler(req, res, function() { 

		// request was not handled...

	});  
});

server.listen(3000)
```

<a name="options" />
### options

The appex runtime accepts the following options.

```javascript
var options = { 
	sourcefile : './program.ts', // (required) location of source file.
    devmode    : true,           // (optional) recompile on request. 
    logging    : true,           // (optional) write requests to stdout.
	stdout     : process.stdout, // (optional) output stream. default is process.stdout
	stderr     : process.stderr, // (optional) error  stream. default is process.stderr
};

var runtime = appex.runtime ( options );
'''

<a name="http_server" />
### http server

Setting up on a nodejs http server.

```javascript
//----------------------------------------------
// file: program.ts
//----------------------------------------------
export module services {
	
	// url: http://localhost:3000/services/message
	export function message (context) { <commit_msg>commit<commit_after>![](https://raw.github.com/sinclairzx81/appex/master/assets/logo.jpg)

### develop nodejs web services with [typescript](http://www.typescriptlang.org/)

## install

```javascript
npm install appex
```

* [overview](#overview)
* [getting started](#getting_started)
	* [runtime](#runtime)
	* [options](#options)
	* [http server](#http_server)
	* [express server](#express_server)
* [developing with appex](#development_mode)
* [functions](#functions)
	* [http handler function](#http_handler_function)
	* [json handler function](#json_handler_function)
	* [public and private functions](#public_private_functions)
	* [the index function](#the_index_function)	
	* [routing with modules and functions](#function_routing)
* [structuring projects](#structuring_projects)
* [typescript resources](#resources)

<a name="overview" />
## overview

Appex is a nodejs web service framework built on top of the TypeScript programming language. Appex 
enables nodejs developers to expose typescript functions as http endpoints as well as generate meaningful service
meta data for clients to consume.

Appex also provides a dynamic compilation environment for typescript to aid in development. Appex will effeciently 
manage compilation in the background without the need to restart the web server, or use addition modules.

Appex is designed to operate as both a standalone web service solution or a compliment an existing applications written
in frameworks such as express / connect.

Appex makes writing http endpoints as easy as writing a functions. 

<a name="getting_started" />
## getting started

The following outlines setting the Appex runtime. 

<a name="runtime" />
### runtime

The Appex runtime is compilation engine that handles compiling typescript code, mapping routes to functions and 
invocation. Appex provides a utility method to setting for setting up the runtime, as described below.

```javascript
var http    = require('http');

var appex   = require('appex');

var runtime = appex.runtime ( { sourcefile : './program.ts' } );

var server  = http.createServer( runtime );

server.listen(3000);
```

The appex.runtime() method returns a http handler function which is both compatable with nodejs' 
http server as well as connect middleware. This is the recommended means of creating runtimes, 
However, if you need to access the runtime directly or are simply curious, you can also setup 
the runtime in the following way...

```javascript
var http    = require('http');

var appex   = require('appex');

var runtime = new appex.Runtime ( { sourcefile : './program.ts' } );

var server  = http.createServer( function(req, res) {
    
	console.log(runtime); // investigate the runtime.

    runtime.request_handler(req, res, function() { 

		// request was not handled...

	});  
});

server.listen(3000)
```

<a name="options" />
### options

The appex runtime accepts the following options.

```javascript
var options = { 
	sourcefile : './program.ts', // (required) location of source file.
    devmode    : true,           // (optional) recompile on request. 
    logging    : true,           // (optional) write requests to stdout.
	stdout     : process.stdout, // (optional) output stream. default is process.stdout
	stderr     : process.stderr, // (optional) error  stream. default is process.stderr
};

var runtime = appex.runtime ( options );
```

<a name="http_server" />
### http server

Setting up on a nodejs http server.

```javascript
//----------------------------------------------
// file: program.ts
//----------------------------------------------
export module services {
	
	// url: http://localhost:3000/services/message
	export function message (context) { 
{'fraction_non_alphanumeric': 0.1292929292929293, 'fraction_numerical': 0.003771043771043771, 'mean_word_length': 3.7817128139085643, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2513137', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1923, 'n_words': 756}