MicroFramework
Micro framework is a bundle of express.js, Mongodb ODM, validator,
dependancy injection framework, configuration framework and restful controllers for
your apps using Typescript.
Usage
Create your main application entry point app.ts
and put there:
import {MicroFrameworkConfig} from "microframework/MicroFrameworkConfig";
import {MicroFrameworkRunner} from "microframework/MicroFrameworkRunner";
let configuration = {
express: {
bodyParser: "json"
},
odm: {
driver: "mongodb",
connection: {
url: "mongodb://localhost:27017/microframework-samples"
}
}
};
new MicroFrameworkRunner(__dirname, configuration)
.run()
.then(result => console.log('Express app is running. Open localhost:3000/questions'))
.catch(error => console.error('Error: ', error));
Now create your first controller in the controller/
directory. Lets call it QuestionController
:
import {Controller, Get} from "type-controllers/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 heard in november' }
];
}
}
Now run your app and open http://localhost:3000/questions
in browser. You should see list of your questions.
Take a look on samples in ./sample
for more examples of usages.
Todos
- cover with tests
- more documentation and samples