{"id":16387490,"url":"https://github.com/mastilver/node-annotation-router","last_synced_at":"2025-04-04T13:28:34.479Z","repository":{"id":26367215,"uuid":"29816411","full_name":"mastilver/node-annotation-router","owner":"mastilver","description":"Bring annotations to your favorite routing framework","archived":false,"fork":false,"pushed_at":"2016-12-23T13:01:32.000Z","size":19,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T15:03:29.668Z","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/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}},"created_at":"2015-01-25T14:19:50.000Z","updated_at":"2015-08-21T12:38:20.000Z","dependencies_parsed_at":"2022-08-28T13:40:30.232Z","dependency_job_id":null,"html_url":"https://github.com/mastilver/node-annotation-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fnode-annotation-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fnode-annotation-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fnode-annotation-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Fnode-annotation-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mastilver","download_url":"https://codeload.github.com/mastilver/node-annotation-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247184360,"owners_count":20897753,"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.807Z","updated_at":"2025-04-04T13:28:34.455Z","avatar_url":"https://github.com/mastilver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-annotation-router [![Build Status](https://travis-ci.org/mastilver/node-annotation-router.svg)](https://travis-ci.org/mastilver/node-annotation-router) [![Coverage Status](https://coveralls.io/repos/mastilver/node-annotation-router/badge.svg)](https://coveralls.io/r/mastilver/node-annotation-router)\n\n\n\u003e Bring annotations to your favorite routing framework\n\n\n## Install\n\n`$ npm install --save annotation-router`\n\n\n## Usage\n\ngiven this file `controller.js`\n\n```\n/*\n    @routePrefix('/api')\n*/\nmodule.exports = {\n\n    // @httpGet()\n    // @route('/collection')\n    collection: function(){\n\n    },\n\n\n    // @route('/collection/{id}')\n    getIndex: function(){\n\n    },\n\n    // @route('/collection')\n    postItem: function(){\n\n    },\n\u003e };\n```\n\n\nYou can then simply retrieve each single route by doing so:\n\n```\n\nvar annotationRouter = require('annotation-router');\n\nannotationRouter('controller.js', function(err, route){\n\n    console.log(route);\n    /*\n        {\n            url: '/api/collection',\n            method: 'GET',\n            action: /* the action function */\n        },\n        ...\n    */\n}, function(err){\n    // all routes have been parsed\n});\n\n```\n\n\n## API\n\n### annotationRouter(paths, eachCallback, finalCallback);\n\n#### paths\n\n*Required*  \nType: `string`, `array`  \n\u003e paths of the all the controllers in the solution that will be checked for routing annotations  \n\u003e check [globby](https://github.com/sindresorhus/globby) for details\n\n\n#### eachCallback(err, route)\n\n##### route.url\n\nType: `string`\n\n\n##### route.method\n\nType: `string`  \nPossible Values: `GET`, `POST`, `PUT`, `DELETE`, `HEAD`  \n\n##### route.action\n\nType: `Function`\n\u003e The action function associated with the route  \n\n#### finalCallback(err)\n\n\n## Annotations API\n\n### @routePrefix(url)\n\n\u003e All the functions inside the module will prepend the `prefixUrl` to theirs urls\n\n\n### @route(url)\n\n\u003e The function following this annotation will be called when someone request the `url`\n\n### @httpGet() and equivalents\n\n\n\u003e Set the method of the route  \n\u003e If none of the available method definition annotation could be found, the route's method will be guessed from the name of the function\n\n\n## Inspiration\n\n[Vatican](https://github.com/deleteman/vatican) is another library which use annotation to define routes. Although it's a standalone library which means you can't use your favorite routing library.\n\nIf you ever work with Microsoft's MVC library, you surely noticed that we are trying to reproduce the same behavior.\n\n\n## Licence\n\nMIT © Thomas Sileghem\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Fnode-annotation-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmastilver%2Fnode-annotation-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Fnode-annotation-router/lists"}