1.0.17 • Published 10 years ago

ccd v1.0.17

Weekly downloads
7
License
ISC
Repository
github
Last release
10 years ago

CCD - ES7 web framework for node

Join the chat at https://gitter.im/codechem/ccd Travis npm npm Maintenance

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

Installation

$ npm install ccd

Example:

//you can bundle the controllers logic in a single or multiple classes
class HelloCtrl extends CCController{
    //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 them
        return 'helloWorld' 
    }
    
    @get('/db')
    getFromDb(req, res){ //simple as that, no callbacks no waiting
        return this.svc.getById(req.params.id)
    }

    @get('/db-more')
    async getFromDb(req, res){ //simple as that, no callbacks no waiting
        let result =  await this.svc.getById(req.params.id)
        //... more work
        return result;
    }
    
    @put('/crash')
    crash(req, res){
        //server will keep working and will return 500 
        throw 'whatever' 
    }

    @get('/async')    
    helloWorldAsync(req, res){
        return new Promise((resolve)=>{
            setTimeout(function() {
                resolve({value:'hello async'});
            }, 200);
        })
    }

    @get('/async-error')    
    async errorWorldAsync(req, res){
        return await new Promise((resolve, reject)=>{
            setTimeout(function() {
                reject('I just crashed in error world');
            }, 200);
        })
    }
}
//Attach the controller to express
const ctrl = new HelloCtrl()
app.use('/', ctrl.router)
app.use('/hello', ctrl.router)
app.listen(3000);

Dependencies

    typescript
    debug
    express>
    mongoose

Plugins

1. ccd-mongo

  • Integration with mongod for rapid development of db driven services
  • npm install ccd-mongo
  • Example:
class UserCtrl extends CCServiceController<User>{
    @post('/login')    
    login(req, res){
        //yes, that simple, 
        //model is regulat mongoose model
        return this.model.findOne(req.body); 
    }
}

//Or If you preffer to separate services and controllers then:
class SpiecesSvc extends CCService<Spiece>{
    ofKind(kind:string){
        return this.model.find({Kind:kind}).exec();
    }
}
//----------
class SpiecesCtrl extends CCController{
    spieces: new SpiecesSvc('Spieces')
    @get('/spieces/:kind') 
    ofKind(req, res){
            return spieces.ofKind(req.params.kind);
    }
}

1. ccd-ng2

  • Provides @ngGenSvc decorator that generates angular2 services for a given CCController

Server:

@ngSvcGen('./client/svc', true)
class HelloCtrl extends CCController{
    @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()
export class HelloCtrlSvc{
    constructor(private rest: SimpleRestService){}

    helloWorld(name){
        return this.rest.get('/hello/'+name);
    }

    doSomething(id, payload){
        return this.rest.post('/'+id, payload);
    }
}

1. ccd-doc

  • Not published yet

Contributors

Costa Halicea|

1.0.17

10 years ago

1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago