2.0.3 • Published 7 years ago

yggdrasil-express v2.0.3

Weekly downloads
13
License
MIT
Repository
github
Last release
7 years ago

Yggdrasil Server

Project which combines express and inversify.

Requirments

Projects which use this library must also use InversifyJS

Guide

Creating a RequestHandler which contains your Router logic.

import 'reflect-meta';
import * as express from 'express';
import {RequestHandler, ExpressRequestHandler, Get} from 'yggdrasil-express';
import {injectable} from 'inversify';

@RequestHandler('/')
@injectable()
class TestController implements ExpressRequestHandler {

  @Get('/')
  public testMethod(response: express.Response): string {
    return 'Random Value';
  }

  @Get('/test')
  public testMethod2(response: express.Response): Promise<string> {
    return Promise.resolve('TestValue');
  }

}

Defining the Controller in the IoC Container:

import {Container} from 'inversify';
import {Types, ExpressRequestHandler} from 'yggdrasil-express';
import {TestController} from './path-to-my-controller';

function start() {
  const container = new Container();
  container.bind<ExpressRequestHandler>(Types.REQUEST_HANDLER).to(TestController).whenTargetName('TestController');

  const app = new YggdrasilServerBuilder(container).build();

  app.listen(8000, (err) => {
    if (err) {
      console.log(err);
    } else {
      console.log('Started');
    }
  });
}

start();
2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago