MicroFramework
Micro framework integrates popular libraries like express.js, Mongodb ODM, validator.ts,
controllers.ts, event-dispatcher.ts
and others for use in your Typescript application. Framework ships by default dependency injection framework and
configuration framework to make all modules to work like a sh
Notice
Library is under active development and API may change from version to version.
Please consider it before using this library.
Quick Start
You use framework with one or more the available modules. Lets say you want to use express.js, Mongodb ODM,
validator, event-dispatcher and restful controllers.
- Install npm modules:
npm install microframework microframework-express microframework-typeodm microframework-controllers.ts microframework-validator.ts microframework-event-dispatcher.ts --save
-
Create app.ts
:
import {MicroFrameworkBootstrapper} from "microframework/MicroFrameworkBootstrapper";
import {ExpressModule} from "microframework-express/ExpressModule";
import {ControllersTsModule} from "microframework-controllers.ts/ControllersTsModule";
import {TypeOdmModule} from "microframework-typeodm/TypeOdmModule";
import {ValidatorTsModule} from "microframework-validator.ts/ValidatorTsModule";
import {EventDispatcherTsModule} from "microframework-event-dispatcher.ts/EventDispatcherTsModule";
new MicroFrameworkBootstrapper({ baseDirectory: __dirname })
.registerModules([
new ExpressModule(),
new TypeOdmModule(),
new ControllersTsModule(),
new ValidatorTsModule(),
new EventDispatcherTsModule()
])
.bootstrap()
.then(result => console.log('Module is running. Open localhost:3000'))
.catch(error => console.error('Error: ', error));
-
Create configuration file configuration/config.yml
:
{
"express": {
"port": "3000",
"bodyParser": {
"type": "json"
}
},
"typeodm": {
"connection": {
"url": "mongodb://localhost:27017/microframework-sample"
}
}
}
-
Now create your first controller, lets say QuestionController: controller/QuestionController.ts
:
import {Controller, Get} from "controllers.ts/Annotations";
import {Response} from "express";
import {Request} from "express";
@Controller()
export class QuestionController {
@Get('/questions')
all(request: Request, response: Response): any[] {
return [
{ title: 'Which processor to choose?', text: 'Which processor is better: Core i5 or Core i7?' },
{ title: 'When new star wars gonna be released?', text: 'When star wars gonna be released? I think in december' }
];
}
}
-
Run your app and open http://localhost:3000/questions
in browser. You should see list of your questions.
Available Modules
Todos
- cover with tests
- more documentation and examples
- more modules