{"id":29097994,"url":"https://github.com/tea-node-js/tea-router","last_synced_at":"2025-06-28T14:08:51.770Z","repository":{"id":34071998,"uuid":"168275707","full_name":"tea-node-js/tea-router","owner":"tea-node-js","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-12T22:52:24.000Z","size":104,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T11:36:23.111Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tea-node-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-30T03:52:31.000Z","updated_at":"2020-01-22T11:35:24.000Z","dependencies_parsed_at":"2022-08-07T23:17:58.875Z","dependency_job_id":null,"html_url":"https://github.com/tea-node-js/tea-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tea-node-js/tea-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tea-node-js%2Ftea-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tea-node-js%2Ftea-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tea-node-js%2Ftea-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tea-node-js%2Ftea-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tea-node-js","download_url":"https://codeload.github.com/tea-node-js/tea-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tea-node-js%2Ftea-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262442471,"owners_count":23311781,"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":"2025-06-28T14:08:51.080Z","updated_at":"2025-06-28T14:08:51.720Z","avatar_url":"https://github.com/tea-node-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tea-router\n\nA router for koa.\n\n# Node version\n\n```\n\u003e= 8\n```\n\n# Usage\n\n```\nnpm install --save tea-router\n```\n\n# Example router definition\n\n```\ncont Koa = require('koa');\nconst Rourer = require('tea-router');\n\n/**\n * @return router instance\n *\n * @params server\n *     new Koa() return result\n * @params controllers\n *     All controllers object,\n *      {\n *        controllerName: {\n *          methodName: method\n *        }\n *      }\n * @params defaultCtl\n *    {\n *      list: function() {},\n *      modify: function() {},\n *      detail: function() {},\n *      remove: function() {},\n *      add: function() {}\n *    }\n * @params opts\n *          apis The uri list all rest api;\n */\nconst server = new Koa();\nconst router = Router(server, controllers, defaultCtl, opts);\n\n```\n\n# Methods\n\n## router[get|post|del|put|patch](path, ctlAct)\n\n```\nrouter.get('/users', 'user#list')\nrouter.post('/users', 'user#addUser')\nrouter.get('/users/:userId', 'user#detail')\nrouter.del('/users/:userId', 'user#remove')\nrouter.put('/users/:userId', 'user#modify')\nrouter.post('/users/:userId', 'user#modify')\n```\n\n## router.resource(name, path)\n\n```\nrouter.resource('user')\n\n// Equivalent to\n// router.get('/users', 'user#list');\n// router.get('/users/:id', 'user#detail');\n// router.put('/users/:id', 'user#modify');\n// router.patch('/users/:id', 'user#modify');\n// router.delete('/users/:id', 'user#remove');\n// router.post('/users', 'user#add');\n```\n\n## router.model(name, path) \n\n```\nrouter.model('user')\n\n// Equivalent to\n// router.get('/users/:id', 'user#detail');\n// router.put('/users/:id', 'user#modify');\n// router.patch('/users/:id', 'user#modify');\n// router.delete('/users/:id', 'user#remove');\n\nrouter.model('user', '/systems/users')\n\n// Equivalent to\n// router.get('/systems/users/:id', 'user#detail');\n// router.put('/systems/users/:id', 'user#modify');\n// router.patch('/systems/users/:id', 'user#modify');\n// router.delete('/systems/users/:id', 'user#remove');\n```\n\n## router.collection(name, path)\n\n```\nrouter.collection('book', null, 'user')\n\n// Equivalent to\n\n// router.get('/users/:userId/books', 'user#books');\n// router.post('/users/:userId/books', 'user#addBook');\n\nrouter.collection('book', '/users/:creatorId/books', 'user')\n\n// Equivalent to\n\n// router.get('/users/:creatorId/books', 'user#books');\n// router.post('/users/:creatorId/books', 'user#addBook');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftea-node-js%2Ftea-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftea-node-js%2Ftea-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftea-node-js%2Ftea-router/lists"}