# Installation

Use npm command in order to install web-service module:

```bash
npm install [--save] web-service
```

# Create backend application in NodeJs

The web-service class allows the developers to build easily backend with NodeJs in a Symfony style:

  - constructor(configurationPath) : build and run a web service following configuration file described by configurationFile or 'conf/web-service.conf.json' if not defined

  Configuration file format:

  ```json
  {
    "port" : 4242,
    "bundles" : [
      {
        "location" : "../bundles/PingBundle",
        "controllers" : [
          {
            "name" : "PingController",
            "routes" : [
              {
                "method" : "GET",
                "url" : "/ping",
                "action" : "ping",
                "parameters" : {}
              }
            ]
          }
        ],
        "services" : []
      }
    ]
  }
  ```

  Bundle folder format:

  |-- Bundle
      |-- controllers
      |-- services

# Usage example

The following example uses the configuration file of "Create backend application in NodeJs" section:

main.js

```js
var WebServiceClass = require('web-service');

var service = new WebServiceClass();
```

ping.controller.js

```js
var q = require('q');

function PingController() {}

PingController.prototype = {
  constructor:PingController,

  ping:function(provider, params, form) {
    var deferred = q.defer();

    deferred.resolve({
      'message' : 'OK'
    });

    return deferred.promise;
  },

};

module.exports = PingController;

```

Tests:

```bash
node main.js
curl http://localhost:4242/ping
OK
```
