# ccd

> Class based web framework on top of Express that uses async await operators to simplify the controllers logic and promote writing clean, simple and maintainable web server

Latest version **1.0.17** (published 2016-11-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install ccd
pnpm add ccd
yarn add ccd
bun add ccd
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.17 |
| Published | 2016-11-11 |
| First published | 2016-10-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Code Chemistry |
| Maintainers | codechem |
| Keywords | ccd, node.js, server, framework, async, await, ecma6, typescript, express |

## Links

- npm: https://www.npmjs.com/package/ccd
- Repository: https://github.com/codechem/ccd
- Homepage: https://github.com/codechem/ccd#readme
- Issues: https://github.com/codechem/ccd/issues
- npm.io page: https://npm.io/package/ccd

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [express](https://npm.io/package/express.md) *
- [typescript](https://npm.io/package/typescript.md) *

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.17 (latest) — 2016-11-11
- 1.0.16 — 2016-11-11
- 1.0.15 — 2016-11-10
- 1.0.14 — 2016-11-06
- 1.0.12 — 2016-11-02
- 1.0.11 — 2016-10-31
- 1.0.10 — 2016-10-31
- 1.0.9 — 2016-10-30
- 1.0.8 — 2016-10-30
- 1.0.7 — 2016-10-29
- 1.0.6 — 2016-10-27
- 1.0.5 — 2016-10-27
- 1.0.4 — 2016-10-27
- 1.0.3 — 2016-10-27
- 1.0.2 — 2016-10-27
- … 2 more at https://npm.io/package/ccd/versions

## README

<img height="100" src="https://raw.githubusercontent.com/codechem/ccd-snippets/master/images/ccdLogo.png"></img>

# CCD - ES7 web framework for node 



[![Join the chat at https://gitter.im/codechem/ccd](https://badges.gitter.im/codechem/ccd.svg)](https://gitter.im/codechem/ccd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Travis](https://img.shields.io/travis/codechem/ccd.svg)]()
[![npm](https://img.shields.io/npm/v/ccd.svg)]()
[![npm](https://img.shields.io/npm/dm/ccd.svg)](https://github.com/codechem/ccd)
[![Maintenance](https://img.shields.io/maintenance/yes/2016.svg)]()

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:

```js
//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](https://github.com/codechem/ccd-mongo)

- Integration with mongod for rapid development of db driven services
- ```npm install ccd-mongo```
- Example:
```typescript
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](https://github.com/codechem/ccd-ng2)

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

#### Server:
```typescript
@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):

```typescript
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](https://github.com/codechem/ccd-doc)

- Not published yet


## Contributors
[Costa Halicea](https://github.com/halicea)|

---
_Source: https://npm.io/package/ccd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
