{"id":16387485,"url":"https://github.com/mastilver/decorator-router","last_synced_at":"2025-04-10T19:42:50.881Z","repository":{"id":72365555,"uuid":"46751412","full_name":"mastilver/decorator-router","owner":"mastilver","description":"framework agnostic router using es7 decorators","archived":false,"fork":false,"pushed_at":"2016-12-23T12:59:02.000Z","size":17,"stargazers_count":4,"open_issues_count":9,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-19T15:03:25.138Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mastilver.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-23T22:16:56.000Z","updated_at":"2024-05-29T09:22:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"98f22d6b-32af-4236-b015-de36cbefa9d1","html_url":"https://github.com/mastilver/decorator-router","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.4,"last_synced_commit":"e33c2b7c950613dac227fd5a06f828aca08a019b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fdecorator-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fdecorator-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fdecorator-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fdecorator-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mastilver","download_url":"https://codeload.github.com/mastilver/decorator-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281420,"owners_count":21077423,"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":[],"created_at":"2024-10-11T04:26:40.459Z","updated_at":"2025-04-10T19:42:50.859Z","avatar_url":"https://github.com/mastilver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# decorator-router [![Build Status](https://travis-ci.org/mastilver/decorator-router.svg?branch=master)](https://travis-ci.org/mastilver/decorator-router)\n\n\u003e Framework agnostic router using es7 decorators\n\n\n## Install\n\n```\n$ npm install --save decorator-router\n```\n\n\n## Usage\n\nGiven a controller  `controller/homeCtrl.js`\n\n```js\nimport {httpGet, middlewareFactory} from 'decorator-router';\n\nconst isLoggedIn = middlewareFactory(function(res, req, next){\n    /*   check if user is logged in   */\n    next();\n});\n\nconst isRole = middlewareFactory(role =\u003e function(res, req, next){\n    /*   check if user have the right role   */\n    next();\n});\n\nexport default {\n\n    @isLoggedIn\n    @httpGet('/')\n    getIndex(req, res){\n        res.ok();\n    },\n\n    @isRole('admin')\n    @httpGet('/admin')\n    getAdminPortal(req, res){\n        res.ok();\n    }\n}\n```\n\nYou can register those routes by doing\n\n```js\nimport decoratorRouter = from 'decorator-router';\nimport decoratorRouterExpress = from 'decorator-router-express';\nimport express from 'express';\n\nlet app = express();\n\ndecoratorRouter('controller/*Ctrl.js', decoratorRouterExpress, app)\n.then(x =\u003e {\n    console.log('done');\n});\n```\n\n\n## API\n\n### decoratorRouter(patterns, strategy, ...strategyParameters)\n\n#### patterns\n\n*Required*  \nType: `string|Array`\n\n[globby](https://github.com/sindresorhus/globby) patterns\n\n#### strategy\n\n*Required*  \nType: `Function`\n\nthe strategy used to register routes. See [available strategies](#strategies)\n\n#### strategyParameters\n\nType: `Array`\n\nThis will be passed to instantiate the strategy.\n\n\n### middlewareFactory(middleware)\n\nReturns a decorator.\n\n## middleware\n\n*Required*  \nType: `Function`\n\nCan be a middleware or a middleware factory depending if you need to pass parameters to your middleware or not.\n\n\n### @httpGet(url)  \n### @httpPost(url)  \n### @httpPut(url)  \n### @httpDelete(url)  \n### @httpHead(url)  \n\n#### url\n\n*Required*  \nType: `string`\n\n\n## Strategies\n\n* [express](https://github.com/mastilver/decorator-router-express)\n\n\n## Inspiration\n\nI originaly wrote [node-annotation-router](https://github.com/mastilver/node-annotation-router)\nAnnotations names are inspired by Microsoft's MVC\n\n\n## License\n\nMIT © [Thomas Sileghem](https://mastilver.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Fdecorator-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmastilver%2Fdecorator-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Fdecorator-router/lists"}