yggdrasil-router
v1.0.0-rc.3
Published
Offers decorators to declare http controllers for express with inversify integration
Downloads
1
Readme
Yggdrasil Router
Requirments
Guide
Declare your Http Controller and Routes:
import 'reflect-meta';
import * as express from 'express';
import {HttpControllerTag, HttpController, Get} from 'yggdrasil-router';
import {injectable} from 'inversify';
@HttpController('/')
@injectable()
class TestController implements HttpControllerTag {
@Get('/')
public testMethod(response: express.Response): string {
return 'Random Value';
}
@Get('/test')
public testMethod2(response: express.Response): Promise<string> {
return Promise.resolve('TestValue');
}
}
Declare the Http Controller in Inversify:
import {interfaces, Container} from 'inversify';
import {YggdrasilServerBuilder, HttpControllerTypes, HttpControllerTag} from 'yggdrasil-router';
import {TestController} from './path-to-my-controller';
function start() {
const container: interfaces.Controller = new Container();
container.bind<HttpControllerTag>(HttpControllerTypes.HTTP_CONTROLLER).to(TestController).whenTargetName('TestController');
const app: express.Application = new YggdrasilServerBuilder(container).build();
app.listen(8000, (err) => {
if (err) {
console.log(err);
} else {
console.log('Started');
}
});
}
start();