{"id":20942082,"url":"https://github.com/salakjs/salak-router","last_synced_at":"2026-04-29T04:31:19.255Z","repository":{"id":65374046,"uuid":"114767275","full_name":"SalakJS/salak-router","owner":"SalakJS","description":"Router for salak base on joi \u0026 koa.","archived":false,"fork":false,"pushed_at":"2019-05-20T02:55:51.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-20T17:18:38.624Z","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/SalakJS.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":"2017-12-19T13:17:44.000Z","updated_at":"2019-05-20T02:55:52.000Z","dependencies_parsed_at":"2023-01-20T00:41:24.370Z","dependency_job_id":null,"html_url":"https://github.com/SalakJS/salak-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/SalakJS%2Fsalak-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalakJS%2Fsalak-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalakJS%2Fsalak-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalakJS%2Fsalak-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SalakJS","download_url":"https://codeload.github.com/SalakJS/salak-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243335382,"owners_count":20274898,"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-18T23:22:20.533Z","updated_at":"2025-12-29T04:45:13.399Z","avatar_url":"https://github.com/SalakJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# salak-router\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![David deps][david-image]][david-url]\n[![NPM download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/salak-router.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/salak-router\n[travis-image]: https://img.shields.io/travis/SalakJS/salak-router.svg?style=flat-square\n[travis-url]: https://travis-ci.org/SalakJS/salak-router\n[david-image]: https://img.shields.io/david/SalakJS/salak-router.svg?style=flat-square\n[david-url]: https://david-dm.org/SalakJS/salak-router\n[download-image]: https://img.shields.io/npm/dm/salak-router.svg?style=flat-square\n[download-url]: https://npmjs.org/package/salak-router\n\n\u003e base on koa-router \u0026 joi\n\n* Support request validate.\n* Support response validate.\n\n## Installation\n\nInstall using [npm](https://www.npmjs.org/):\n\n```sh\nnpm install --save salak-router\n```\n\n## API Reference\n\n* salak-router\n  * Router (extends koa-router)  \n        * new Router([opts])  \n        * _instance_  \n            * .addRoute(opts, handler)\n\n\n### Router\n\n#### new Router([opts])\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| [opts] | \u003ccode\u003eObject\u003c/code\u003e |  |\n| [opts.prefix] | \u003ccode\u003eString\u003c/code\u003e | prefix router paths |\n| [opts.requestFailure] | \u003ccode\u003eNumber\u003c/code\u003e | request validation error status |\n| [opts.responseFailure] | \u003ccode\u003eString\u003c/code\u003e | response validation error status|\n\n\n#### .addRoute(opts, handler)\n\nadd route for app\n\n| Param | Type | Description |\n| --- | --- | --- |\n| opts | \u003ccode\u003eObject\u003c/code\u003e | |\n| opts.path | \u003ccode\u003eString\u003c/code\u003e | router path |\n| opts.method | \u003ccode\u003eArray|String\u003c/code\u003e | router method |\n| opts.validate | \u003ccode\u003eObject\u003c/code\u003e | router validation schema |\n| handler | \u003ccode\u003eFunction\u003c/code\u003e | router handler |\n\n## Example\n\n```\nconst Koa = require('koa')\nconst Router = require('salak-router')\nconst Joi = Router.Joi\n\nconst app = new Koa()\nconst router = new Router()\n\nrouter.addRoute({\n  path: '/test',\n  method: 'GET',\n  validate: {\n    query: {\n      id: Joi.number().required().description('文章id')\n    },\n    responses: {\n      200: {\n        body: Joi.object().keys({\n          code: Joi.number(),\n          msg: Joi.string()\n        }).description('文章详情')\n      }\n    }\n  }\n}, async (ctx) =\u003e {\n  ctx.body = {\n    code: 0,\n    msg: 'ok'\n  }\n})\n\napp.use(router.routes())\n\napp.listen(3000)\n```\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalakjs%2Fsalak-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalakjs%2Fsalak-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalakjs%2Fsalak-router/lists"}