{"id":22688914,"url":"https://github.com/benoitclaveau/damless","last_synced_at":"2025-08-07T02:31:16.092Z","repository":{"id":57211382,"uuid":"127115343","full_name":"BenoitClaveau/damless","owner":"BenoitClaveau","description":"Streamify your node.js web server.","archived":false,"fork":false,"pushed_at":"2021-04-02T07:57:10.000Z","size":1294,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-27T09:17:04.672Z","etag":null,"topics":["api","compress","compression","json","nodejs","services","stream","streamify","webserver"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenoitClaveau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-28T09:17:40.000Z","updated_at":"2021-04-02T07:57:12.000Z","dependencies_parsed_at":"2022-08-30T12:30:26.278Z","dependency_job_id":null,"html_url":"https://github.com/BenoitClaveau/damless","commit_stats":null,"previous_names":["benoitclaveau/dam-less","benoitclaveau/dambreaker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenoitClaveau%2Fdamless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenoitClaveau%2Fdamless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenoitClaveau%2Fdamless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenoitClaveau%2Fdamless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenoitClaveau","download_url":"https://codeload.github.com/BenoitClaveau/damless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228982227,"owners_count":18001488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","compress","compression","json","nodejs","services","stream","streamify","webserver"],"created_at":"2024-12-10T00:16:32.064Z","updated_at":"2024-12-10T00:16:32.558Z","avatar_url":"https://github.com/BenoitClaveau.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DamLess\n\nDamLess help you to create a NodeJS stream api (with http chunk).\n\nDevelop your http server like a gulp script. \n\n [![NPM][npm-image]][npm-url]\n [![Build Status][travis-image]][travis-url]\n [![Coverage Status](https://coveralls.io/repos/github/BenoitClaveau/damless/badge.svg?branch=master)](https://coveralls.io/github/BenoitClaveau/damless?branch=master)\n [![NPM Download][npm-image-download]][npm-url]\n [![Dependencies Status][david-dm-image]][david-dm-url]\n\n\n```server.js\nconst DamLess = require(\"damless\");\nconst damless = new DamLess();\ndamless\n    .config({ http: { port: 3000 }})\n    .inject(\"info\", \"./services/info\")\n    .inject(\"user\", \"./services/user\")\n    .get(\"/helloworld\", \"info\", \"helloworld\")\n    .post(\"/user\", \"user\", \"insertOne\")\n    .start();\n```\n\n```./services/info.js\nclass Info {\t\n    // helloworld is declare as GET:/helloworld\n    helloworld(context, stream, headers) {\n        stream.write(\"Hello\");\n        stream.end(\"world\");\n    }\n}\n```\n\n```./services/user.js\nconst { Transform } = require(\"stream\");\nclass User {\t\n    insertOne(context, stream, headers) {\n        // Read a JSON stream request and write a response as a JSON stream.\n        stream\n            .pipe(new Transform({\n                objectMode: true,\n                transform(chunk, enc, callback) {\n                    // save the chunk (user) in the database\n                    callback(null, chunk);\n                }\n            }))\n            .pipe(stream);\n    }\n}\n```\n\n```shell\nnpm install damless --save\n```\n\n\n# Features\n  \n  [Dependency Injection](#di)\n\n  [(context, stream, headers) like http2 interface](#ask-reply)\n\n\n## Services/info.js \u003ca href=\"#services\" /\u003e\n\n```services/info.js\nclass ServiceInfo {\t\n};\n\ntext(context, stream, headers) {\n  stream.write(\"Hello\");\n  stream.end(\"world\")\n};\n\njson(context, stream, headers) {\n  stream.write({ name: \"peter\" });\n  stream.end({ name: \"folk\" });\n};\n\nexports = module.exports = ServiceInfo;\n```\n\n## Dependency Injection \u003ca href=\"#di\" /\u003e\n\nDamLess use [givemetheservice](https://www.npmjs.com/package/givemetheservice) to inject all services.\n\nYou can override all damless functions or inject your new services.\n\nIt's is easier to test your api.\n\n## (context, stream, headers) -\u003e http2 interface \u003ca href=\"#ask-reply\" /\u003e\n\nDamLess has been inspired by the http2 syntax. The request and response are wrap by an unique duplex stream.\nThis stream automatically stringify, gzip or deflate your response. It is useless to pipe a compressor.\n\n## Extend services \u003ca href=\"#oop\" /\u003e\n\nUse the power of ES6 to easily extends services.\n\n```json.js\nconst { Json } = require(\"damless\");\nconst moment = require(\"moment\");\nconst { ObjectID } = require(\"bson\");\n\nclass CustomJson extends Json {\n\n    constructor() {\n        super();\n    }\n\n    // override the default onValue to deserialize mongo ObjectID\n    onValue(key, value) {\n        if (/\\d{2}-\\d{2}-\\d{2}/.test(value)) return moment(value, \"YYYY-MM-DD\").toDate();\n        if (ObjectID.isValid(value)) return new ObjectID(value);\n        return super.onValue(key, value);\n    }\n}\n\nexports = module.exports = CustomJson;\n```\n\nThe default json serializer is declared in the DI as \"json\". Replace it to load your service.\n\n```server.js\ndamless\n    .inject(\"json\", \"./custom-json.js\")\n```\n\n## Develop faster\n  \n  * [mongo](https://www.npmjs.com/package/damless-mongo)\n  * [nodemailer](https://www.npmjs.com/package/damless-nodemailer)*\n\n## Configuration manager (damless.json) \u003ca href=\"#config\" /\u003e\n\nYou can configure damless in javascript or via json file.\n\n```server.js\ndamless\n    .config(\"./damless.json\")\n    .config({ http: { port: 3000 }})\n    .config(config =\u003e {\n        config.env = \"dev\"\n    })\n```\n\n```damless.json\n{\n    \"services\": \"./services.json\",\n    \"http\": {\n        \"port\": 3000\n    }\n}\n```\nYou can declare your services in an other json file.\n\n```services.json\n{\n    \"services\": [\n        {\n            \"name\": \"info\",\n            \"location\": \"./services/info\"\n        }\n    ],\n    \"http-routes\": [\n        {\n            \"get\": \"/\",\n            \"service\": \"info\",\n            \"method\": \"text\"\n        }\n    ]\n}\n```\n\nRetrieve the config object in your service.\n\n```.js\nclass ServiceInfo {\n    // config will be injected by our DI\n    constructor(config) {\n        console.log(config.http.port);\n    }\n};\n```\n\n## You want to see some examples\n\nTo run our examples, clone the Damless repo and install the dependencies.\n\n```bash\n$ git clone https://github.com/BenoitClaveau/damless --depth 1\n$ cd damless\n$ npm install\n$ cd exemples/helloworld\n$ node server.js\n```\n\n## Test\n\nTo run our tests, clone the Damless repo and install the dependencies.\n\n```bash\n$ git clone https://github.com/BenoitClaveau/damless --depth 1\n$ cd damless\n$ npm install\n$ cd tests\n$ node.exe \"../node_modules/mocha/bin/mocha\" .\n```\n\n[npm-image]: https://img.shields.io/npm/v/damless.svg\n[npm-image-download]: https://img.shields.io/npm/dm/damless.svg\n[npm-url]: https://npmjs.org/package/damless\n[travis-image]: https://travis-ci.org/BenoitClaveau/damless.svg?branch=master\n[travis-url]: https://travis-ci.org/BenoitClaveau/damless\n[coveralls-image]: https://coveralls.io/repos/BenoitClaveau/damless/badge.svg?branch=master\u0026service=github\n[coveralls-url]: https://coveralls.io/github/BenoitClaveau/damless?branch=master\n[david-dm-image]: https://david-dm.org/BenoitClaveau/damless/status.svg\n[david-dm-url]: https://david-dm.org/BenoitClaveau/damless\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitclaveau%2Fdamless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenoitclaveau%2Fdamless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitclaveau%2Fdamless/lists"}