Skip to content

Repository files navigation

CCD - ES7 web framework for node

Join the chat at https://gitter.im/codechem/ccdTravisnpmnpmMaintenance

Expressive, class based approach web framework. It uses the latest ES7 features like async/await and decorators to make writing web apps and apis simple and fun. It can be used thru typescript only at the moment

Important

This framework is not actively developed for couple of years now and should not be used in production.

It stays here for historical reasons as the first(to my knowledge) framework with async-await and decorators support (through typescript at the time).

Additionally, it may be a good resource for learning due to its relatively small code base.

Installation

$ npm install ccd

Example:

//you can bundle the controllers logic in a single or multiple classesclassHelloCtrlextendsCCController{//use decorators on the controllers to 
@get('/hello')//or get('/hello', ...any middleware methods)helloWorld(req,res){//return anything, object|(err,data)=void, promise .. it works with all of themreturn'helloWorld'}
@get('/db')getFromDb(req,res){//simple as that, no callbacks no waitingreturnthis.svc.getById(req.params.id)}
@get('/db-more')asyncgetFromDb(req,res){//simple as that, no callbacks no waitingletresult=awaitthis.svc.getById(req.params.id)//... more workreturnresult;}
@put('/crash')crash(req,res){//server will keep working and will return 500 throw'whatever'}
@get('/async')helloWorldAsync(req,res){returnnewPromise((resolve)=>{setTimeout(function(){resolve({value:'hello async'});},200);})}
@get('/async-error')asyncerrorWorldAsync(req,res){returnawaitnewPromise((resolve,reject)=>{setTimeout(function(){reject('I just crashed in error world');},200);})}}//Attach the controller to expressconstctrl=newHelloCtrl()app.use('/',ctrl.router)app.use('/hello',ctrl.router)app.listen(3000);

Dependencies

 typescript
debug
express>
mongoose

Plugins

  • Integration with mongod for rapid development of db driven services
  • npm install ccd-mongo
  • Example:
classUserCtrlextendsCCServiceController<User>{
@post('/login')login(req,res){//yes, that simple, //model is regulat mongoose modelreturnthis.model.findOne(req.body);}}//Or If you preffer to separate services and controllers then:classSpiecesSvcextendsCCService<Spiece>{ofKind(kind:string){returnthis.model.find({Kind:kind}).exec();}}//----------classSpiecesCtrlextendsCCController{spieces: newSpiecesSvc('Spieces')
@get('/spieces/:kind')ofKind(req,res){returnspieces.ofKind(req.params.kind);}}
  • Provides @ngGenSvc decorator that generates angular2 services for a given CCController

Server:

@ngSvcGen('./client/svc',true)classHelloCtrlextendsCCController{
@get('/hello/:name')helloWorld(req,res){return`hello ${req.params.name}`}
@post('/:id')doSomething(req,res){return ....}
...
}

Output(Angular 2 service):

import{Injectable}from'@angular/core';import{SimpleRestService}from'ccNgRest';
@Injectable()exportclassHelloCtrlSvc{constructor(privaterest: SimpleRestService){}helloWorld(name){returnthis.rest.get('/hello/'+name);}doSomething(id,payload){returnthis.rest.post('/'+id,payload);}}
  • Not published yet

Contributors

Costa Halicea|

About

ES7 Node web framework

Resources

Stars

18 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages