{"id":22059253,"url":"https://github.com/opentable/decorouter","last_synced_at":"2025-07-24T00:31:42.267Z","repository":{"id":42218423,"uuid":"59621822","full_name":"opentable/decorouter","owner":"opentable","description":"Simple decorator based es6 class method routing for express nodejs","archived":true,"fork":false,"pushed_at":"2016-06-10T02:45:21.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-06-11T19:49:18.289Z","etag":null,"topics":[],"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/opentable.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":"2016-05-25T01:43:40.000Z","updated_at":"2024-09-05T14:20:42.000Z","dependencies_parsed_at":"2022-08-27T12:11:51.320Z","dependency_job_id":null,"html_url":"https://github.com/opentable/decorouter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/opentable/decorouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fdecorouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fdecorouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fdecorouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fdecorouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentable","download_url":"https://codeload.github.com/opentable/decorouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fdecorouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265705568,"owners_count":23814485,"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-11-30T17:27:44.490Z","updated_at":"2025-07-24T00:31:41.992Z","avatar_url":"https://github.com/opentable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Decorouter\n===================\n\nSimple decorator based es6 class method routing for express nodejs\n\n[![NPM version](https://badge.fury.io/js/decorouter.png)](http://badge.fury.io/js/decorouter)\n[![Build Status](https://travis-ci.org/opentable/decorouter.png?branch=master)](https://travis-ci.org/decorouter/spur-ioc)\n\n## Installation\n\n```bash\n$ npm install decorouter --save\n```\n\n## Usage\n\nusage requiring [babel-plugin-transform-decorators-legacy](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy)  with babel 6\n\n```javascript\nimport { Route } from '../decorouter';\n\nexport class Controller\n{\n    constructor() {\n        //usage not requiring babel-plugin-transform-decorators-legacy\n        Route('get','/methodWithoutDecorator')(this, 'methodWithoutDecorator');\n    }\n\n    //additional handlers can be added after route eg (req, res, next) =\u003e next()\n    @Route('get', '/method')\n    method(req, res) {\n        res.send({from: 'method'});\n    }\n\n    //async methods can (and probably should) be used where neccessary\n    @Route('get', '/methodAsync')\n    async methodAsync(req, res) {\n        res.send({from: 'methodAsync'});\n    }\n\n    //additional handlers can be added after route eg (req, res, next) =\u003e next()\n    @Route('get', '/methodWithAdditionalHandler', (req, res, next) =\u003e { res.handlerCalled = true; next();})\n    methodWithAdditionalHandler(req, res) {\n        res.send({\n            from: 'methodWithAdditionalHandler',\n            handlerCalled: res.handlerCalled});\n    }\n\n    methodWithoutDecorator(req, res) {\n        res.send({from: 'methodWithoutDecorator'});\n    }\n\n    //will defaut to 'get' and '/defaultRouteAssignedByMethodName'\n    @Route()\n    defaultRouteAssignedByMethodName(req, res) {\n       res.send({from: 'defaultRouteAssignedByMethodName'});\n    }\n\n}\n```\n\nRegistering routes\n```javascript\nimport { addRoutes, addRoutesFromDir } from 'decorouter';\nimport express from 'express';\nimport { Controller } from './testControllers';\n\nlet router = express.Router();\naddRoutes(router, () =\u003e new Controller());\n\n//or all in this directory\naddRoutesFromDir(router, module, (typeObject) =\u003e new typeObject());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fdecorouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentable%2Fdecorouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fdecorouter/lists"}