<commit_before># Typescript API for RESTful Services for (Node.js)

[![Build Status](https://travis-ci.org/igorzg/typeix.svg?branch=master)](https://travis-ci.org/igorzg/typeix)
[![npm version](https://badge.fury.io/js/typeix.svg)](https://badge.fury.io/js/typeix)

* Works with node gte 6.x.x
* Typeix has dependency injection inspired by Angular 2


[View demo application](https://github.com/igorzg/typeix/tree/master/demo-app)

## Features
* Dependency Injection
* Modular design
* MVC structure
* Component driven -> singletons -> depends on injection level
* Request Filters
* Nice routing features -> supports static && dynamic routing
* Controller inheritance


## Getting started
#### create project

```npm
npm init
```

```npm
npm install typeix --save
```

#### create controllers/core.controller.ts

```typescript
import { Controller, Action, isPresent } from "typeix";
import { readFile } from "fs";
import { normalize } from "path";

@Controller({
  name: "core" // route controller
})
export class CoreController {
  
  @Action("favicon") // route action
  async faviconLoader() {
    return await <Promise<Buffer>> new Promise(
      (resolve, reject) =>
        readFile(
          normalize(__dirname + "/pathto/my/favicon.ico"),
          (err, data) => isPresent(err) ? reject(err) : resolve(data)
        )
    );
  }
  
  @Action("index")
  myIndexAction() {
    return "Hello world"; // accepts - string // buffer // Promise<string|Buffer>
  }
}

```

#### create application.module.ts
```typescript
import { Module, Router, Inject, IAfterConstruct, Methods } from "typeix"
import { CoreController } from "./controllers/core.controller"

@Module({
  controllers: [CoreController],
  providers: [Router]
})
class Application implements IAfterConstruct {
  
  @Inject(Router)
  private router: Router;
  
  afterConstruct() {
    // just controller/action always points to root module
    this.router.addRules([
        {
          methods: [Methods.GET],
          // module/controller/action or controller/action
          route: "core/favicon", 
          url: "/favicon.ico"
        },
        {
          methods: [Methods.GET],
           // equals root/core/index since bootstrap module is root module
          route: "core/index",
          url: "/"
        }
    ]);
  }
  
}
```

#### create bootstrap.ts
```typescript
import {Application} from "./application.module";
import {httpServer} from "typeix";

/**
 * Bootstrap http or https server.
 *
 * @description
 * Creates server instance on port 9000
 * We always use separate bootstrap file to bootstrap application 
 * because of testing or server side fakeHttp feature.
 * We will be able to simulate server side request with fakeHttp
 */
httpServer(Application, 9000);
```
<commit_msg>Update of readme<commit_after># Typescript API for RESTful Services for (Node.js)

[![Build Status](https://travis-ci.org/igorzg/typeix.svg?branch=master)](https://travis-ci.org/igorzg/typeix)
[![npm version](https://badge.fury.io/js/typeix.svg)](https://badge.fury.io/js/typeix)

* Works with node gte 6.x.x
* Typeix has dependency injection inspired by Angular 2


[View demo application](https://github.com/igorzg/typeix/tree/master/demo-app)

## Features
* Dependency Injection
* Modular design
* MVC structure
* Component driven -> singletons -> depends on injection level
* Request Filters
* Nice routing features -> supports static && dynamic routing
* Controller inheritance


## Getting started
#### create project

```npm
npm init
```

```npm
npm install typeix --save
```

#### create controllers/core.controller.ts

```typescript
import { Controller, Action, isPresent } from "typeix";
import { readFile } from "fs";
import { normalize } from "path";

@Controller({
  name: "core" // route controller
})
export class CoreController {
  
  @Action("favicon") // route action
  async faviconLoader() {
    return await <Promise<Buffer>> new Promise(
      (resolve, reject) =>
        readFile(
          normalize(__dirname + "/pathto/my/favicon.ico"),
          (err, data) => isPresent(err) ? reject(err) : resolve(data)
        )
    );
  }
  
  @Action("index")
  myIndexAction() {
    return "Hello world"; // accepts - string // buffer // Promise<string|Buffer>
  }
}

```

#### create application.module.ts
```typescript
import { Module, Router, Inject, IAfterConstruct, Methods } from "typeix"
import { CoreController } from "./controllers/core.controller"

@Module({
  controllers: [CoreController],
  providers: [Router]
})
class Application implements IAfterConstruct {
  
  @Inject(Router)
  private router: Router;
  
  afterConstruct() {
    // just controller/action always points to root module
    this.router.addRules([
        {
          methods: [Methods.GET],
          // module/controller/action or controller/action
          route: "core/favicon", 
          url: "/favicon.ico"
        },
        {
          methods: [Methods.GET],
           // equals root/core/index since bootstrap module is root module
          route: "core/index",
          url: "/"
        }
    ]);
  }
  
}
```

#### create bootstrap.ts
```typescript
import {Application} from "./application.module";
import {httpServer} from "typeix";

/**
 * Bootstrap http or https server.
 *
 * @description
 * Creates server instance on port 9000
 * We always use separate bootstrap file to bootstrap application 
 * because of testing or server side fakeHttp feature.
 * We will be able to simulate server side request with fakeHttp
 */
httpServer(Application, 9000);
```

To start your application run node bootstrap.js after compiling to javascript.

{'fraction_non_alphanumeric': 0.1321257325519446, 'fraction_numerical': 0.003551767004084532, 'mean_word_length': 3.2699014404852162, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, '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': '7598989', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1615, 'n_words': 475}