DamLess help you to create a NodeJS stream api (with http chunk).
Develop your http server like a gulp script.
You can override all damless functions or inject your new services.
It's is easier to test your api.
Use the power of ES6 to easily extends services.
const { Json } = require("damless");
const moment = require("moment");
const { ObjectID } = require("bson");
class CustomJson extends Json {
constructor() {
super();
}
// override the default onValue to deserialize mongo ObjectID
onValue(key, value) {
if (/\d{2}-\d{2}-\d{2}/.test(value)) return moment(value, "YYYY-MM-DD").toDate();
if (ObjectID.isValid(value)) return new ObjectID(value);
return super.onValue(key, value);
}
}
exports = module.exports = CustomJson;
The default json serializer is declared in the DI as "json". Replace it to load your service.
damless
.inject("json", "./custom-json.js")
Develop faster
You can configure damless in javascript or via json file.
damless
.config("./damless.json")
.config({ http: { port: 3000 }})
.config(config => {
config.env = "dev"
})
{
"services": "./services.json",
"http": {
"port": 3000
}
}
You can declare your services in an other json file.
{
"services": [
{
"name": "info",
"location": "./services/info"
}
],
"http-routes": [
{
"get": "/",
"service": "info",
"method": "text"
}
]
}
Retrieve the config object in your service.
class ServiceInfo {
// config will be injected by our DI
constructor(config) {
console.log(config.http.port);
}
};
You want to see some examples
To run our examples, clone the Damless repo and install the dependencies.
$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd exemples/helloworld
$ node server.js
Test
To run our tests, clone the Damless repo and install the dependencies.
$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd tests
$ node.exe "../node_modules/mocha/bin/mocha" .