{"id":15097843,"url":"https://github.com/cupcakearmy/koa-router","last_synced_at":"2025-10-08T02:31:51.068Z","repository":{"id":57195281,"uuid":"100867868","full_name":"cupcakearmy/koa-router","owner":"cupcakearmy","description":"Koa Router","archived":true,"fork":false,"pushed_at":"2018-02-25T13:06:34.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T02:57:06.039Z","etag":null,"topics":["koa","koa-middleware","path","regex","router"],"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/cupcakearmy.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-08-20T14:43:45.000Z","updated_at":"2023-01-28T10:10:54.000Z","dependencies_parsed_at":"2022-09-16T05:21:31.492Z","dependency_job_id":null,"html_url":"https://github.com/cupcakearmy/koa-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cupcakearmy/koa-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fkoa-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fkoa-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fkoa-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fkoa-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cupcakearmy","download_url":"https://codeload.github.com/cupcakearmy/koa-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fkoa-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278877657,"owners_count":26061490,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["koa","koa-middleware","path","regex","router"],"created_at":"2024-09-25T16:40:54.424Z","updated_at":"2025-10-08T02:31:50.752Z","avatar_url":"https://github.com/cupcakearmy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Koa Router\n\n[![npm](https://img.shields.io/npm/v/cca-koa-router.svg)](https://www.npmjs.com/package/cca-koa-router)\n[![npm](https://img.shields.io/npm/dt/cca-koa-router.svg)]()\n[![npm](https://img.shields.io/npm/l/cca-koa-router.svg)]()\n[![Travis](https://img.shields.io/travis/CupCakeArmy/koa-router.svg)]()\n\nKoa Router with support for recursive nesting and regexp and dynamic urls. No dependecies and lightweight code.\n\n### Install\n```bash\nnpm install cca-koa-router --save\n```\n\n### QA\n\nIf you have questions:\n\n[![Join the chat at https://gitter.im/cupcakearmy/koa-router](https://badges.gitter.im/cupcakearmy/koa-router.svg)](https://gitter.im/cupcakearmy/koa-router?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n### Simple Example\n```javascript\nconst\n\tKoa = require('koa'),\n\trouter = require('cca-koa-router')\n\nconst\n\tapp = new Koa(),\n\tport = 3000\n\napp.use(router(_ =\u003e {\n\t_.get('/user/:user', (c, n) =\u003e {\n\t\tc.body = c.request.params['user']\n\t\t// GET /user/foo =\u003e 'foo'\n\t})\n}))\n\napp.listen(port)\n```\n\n## Documentation\n\n- [Options](#options)\n- [Modes](#modes)\n- [Nesting](#nesting)\n- [Methods](#methods)\n- [Parameters](#params)\n\n##### ~ `router(options, builder)`\n\n##### Options:\n\n- `prefix` Prefix for the paths\n- `end` If trailing paths sould be counted\n- `case` Case sentitive\n\n###### Default\n```javascript\n{\n  prefix: '',\n  end: false,\n  case: false\n}\n```\n\n##### Modes:\n1. `router(builder)` No options specified, use default\n2. `router('string', builder)` String will be taken as the prefix\n3. `router({}, builder)` Specify custom options\n\n###### Example\n```javascript\n// 1\napp.use(router(_ =\u003e {\n\t_.get('/mypath', (c, n) =\u003e {\n\t\t// GET /mypath\n\t\tc.body = 'Some Response'\n\t})\n}))\n\n// 2\napp.use(router('/myprefix', _ =\u003e {\n\t_.get('/mypath', (c, n) =\u003e {\n\t\t// GET /myprefix/mypath\n\t\tc.body = 'Some Response'\n\t})\n}))\n\n// 3\napp.use(router({\n\tprefix: '/myprefix',\n\tcase: true\n}, _ =\u003e {\n\t_.get('/myPath', (c, n) =\u003e {\n\t\t// GET /myprefix/myPath\n\t\tc.body = 'Some Response'\n\t})\n}))\n````\n\n##### Nesting\nYou can nest recursively `routers`. Each can have its own `options`.\n\n###### Example\n\n```javascript\napp.use(router(_ =\u003e {\n\t_.nest(router('/user', _ =\u003e {\n\t\t_.get('/view', (c, n) =\u003e {\n\t\t\tc.body = 'View User'\n\t\t})\n\n\t\t_.get('/edit', (c, n) =\u003e {\n\t\t\tc.body = 'Edit User'\n\t\t})\n\t}))\n\n\t_.get('/', c =\u003e {\n\t\tc.body = 'Root'\n\t})\n}))\n\n/*\nGET / =\u003e 'Root'\nGET /user/view =\u003e 'View User'\nGET /user/edit =\u003e 'Edit User'\n*/\n```\n\n##### Methods\nSupported methods:\n- `GET`\n- `POST`\n- `PUT`\n- `PATCH`\n- `DELETE`\n\nSpecial \"methods\":\n- `ALL` Used if none other method is defined\n- `NEST` Used to nest layers of the router\n\n###### Example\n```javascript\napp.use(router(_ =\u003e {\n\t_.get('/path', c =\u003e {\n\t\tc.body = 'GET'\n\t})\n\t_.post('/path', c =\u003e {\n\t\tc.body = 'POST'\n\t})\n\t\n\t// ...\n\t\n\t_.delete('/path', c =\u003e {\n\t\tc.body = 'DELETE'\n\t})\n}))\n```\n\n##### Params\nThe `router` suppors parametrs in the url/path. Parameters will be stored in the `ctx.request.params` object\n\n###### Example\n```javascript\napp.use(router(_ =\u003e {\n\t_.get('/user/:user/:id/view/:type', (c, n) =\u003e {\n\t\tc.body = c.request.params\n\t})\n}))\n\n/*\nGET /user/foo/123/view/active\n=\u003e \n{\"user\":\"foo\",\"id\":\"123\",\"type\":\"active\"}\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcupcakearmy%2Fkoa-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcupcakearmy%2Fkoa-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcupcakearmy%2Fkoa-router/lists"}