# pigalle-mvc

> Build quickly NodeJS/Express.js RESTful applications using the Pigalle collection of decorators!

Latest version **0.0.1** (published 2016-11-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install pigalle-mvc
pnpm add pigalle-mvc
yarn add pigalle-mvc
bun add pigalle-mvc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-11-11 |
| First published | 2016-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 9 Février |
| Maintainers | 9fevrier |
| Keywords | pigalle, framework, rest, decorators, mvc, json, restful, services, es6 |

## Links

- npm: https://www.npmjs.com/package/pigalle-mvc
- Repository: https://github.com/9fevrier/pigalle-mvc
- Homepage: https://github.com/9fevrier/pigalle-mvc#readme
- Issues: https://github.com/9fevrier/pigalle-mvc/issues
- npm.io page: https://npm.io/package/pigalle-mvc

## Dependencies (6)

- [sha1](https://npm.io/package/sha1.md) ^1.1.1
- [bunyan](https://npm.io/package/bunyan.md) ^1.7.1
- [express](https://npm.io/package/express.md) ^4.14.0
- [node-uuid](https://npm.io/package/node-uuid.md) ^1.4.7
- [pigalle-core-alpha](https://npm.io/package/pigalle-core-alpha.md) ^0.4.0
- [pigalle-promises-control-flow](https://npm.io/package/pigalle-promises-control-flow.md) 0.0.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.1 (latest) — 2016-11-11

## README

# Pigalle Rest [![Build Status](https://travis-ci.org/9fevrier/pigalle-rest.svg?branch=master)](https://travis-ci.org/9fevrier/pigalle-rest)

Quickly reate NodeJS/Express.js RESTful applications using the Pigalle collection of decorators!

## Requires

* [NodeJS](http://nodejs.org) >= 5.7.0 
* [Pigalle Container](https://github.com/9fevrier/pigalle-container)

## Installation 

    npm install pigalle-rest

## Tests

    npm test
    
## Build

    npm install
    gulp babel
   
## Live development

    gulp watch
   
## Usage

## Example

See the example: `test/testApp/`

### Controller: `app/controller.js`

    import {Autowired, Component, container} from 'pigalle-container';
    import {RequestMapping, RequestMethod} from 'pigalle-rest';
    
    @Autowired()
    @Component('restControllerComponent')
    export default class Controller {
      constructor() {
        this._memoryDB = ['item1'];
      }
    
      @RequestMapping({value: '/api/items', method: RequestMethod.GET})
      list(req, res, next) {
        return res.json(this._memoryDB);
      }
    
      @RequestMapping({value: '/api/item', method: RequestMethod.POST})
      create(req, res, next) {
        const data = req.body;
        if (data.item) {
          this._memoryDB.push(data.item);
        }
        return res.json(data)
      }
    }

### ExpressJS server: `server.js`

    import express from 'express';
    import path from 'path';
    import http from 'http';
    import util from 'util';
    import bodyParser from 'body-parser';
    
    import {container} from 'pigalle-container';
    import {RestRunner} from 'pigalle-rest';
    
    // The ExpressJS application.
    const app = express();
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));
    
    
    // The application directory.
    const appDir = path.join(__dirname, 'app/');
    
    // The REST router!
    const restRunner = RestRunner.instance;
    restRunner.app = app;
    restRunner.native = new express.Router(); // The native express router.
    
    // Run the REST application!
    container.scan(appDir).run().inject().run().done((instance) => {
      restRunner.initializeRouter().run().done((restRunner) => {
    
        const server = http.createServer(app);
        server.listen(3000, () => {
          console.log('Server is listening: http://localhost:3000/');
        });
    
      }).error((err) => {
        console.log('Error when initialize Pigalle RestRunner: ' + err.stack);
      });
    
    }).error((err) => {
      console.log('Error when initialize container: ' + err.stack);
    });

### Run application

    node ./node_modules/babel-cli/bin/babel-node.js \
        --presets es2015,stage-1 \
        --plugins transform-decorators-legacy \
        test/testApp/server.js
        
### Call services

* `GET /api/items` to obtain the list of items 
* `POST /api/item` to add an item to list

## Change history

### v0.1.0 (2016-09-28)

* Transform `RestRunner` as a real singleton.
* The attribute `nativeRouter` of `RestRunner` has been renamed to `native`.
* By using the unique container now provided by pigalle-container:
  * `setContainer` method has been removed in the `RestRunner` class;
  * `@RequestMapping`: the `container` parameter has been removed.
  * `@RequestMapping`: the `component` parameter has been removed (automatic binding).
* Upgrade dependencies: 
  * babel-cli@6.14.0
  * babel-preset-es2015@6.14.0
* Upgrade README.

### v0.0.2

* Add `preprocess` argument in `@RequestMapping`.

### v0.0.1

Initial version including:

* `RequestMapping` decorator
* `RequestMethod` enum

## License


    The MIT License (MIT)
    
    Copyright (c) 2016 9 Février <contact@9fevrier.com>
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

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