{"id":13779761,"url":"https://github.com/koajs/path-match","last_synced_at":"2025-05-07T06:05:17.551Z","repository":{"id":18917615,"uuid":"22136515","full_name":"koajs/path-match","owner":"koajs","description":"koa route middleware","archived":false,"fork":false,"pushed_at":"2025-04-28T01:13:43.000Z","size":1173,"stargazers_count":36,"open_issues_count":4,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-29T06:23:37.098Z","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/koajs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-07-23T07:34:32.000Z","updated_at":"2025-03-20T05:25:44.000Z","dependencies_parsed_at":"2024-11-06T08:34:19.736Z","dependency_job_id":"daaf44b8-8db6-4a44-b9b6-00b2de162895","html_url":"https://github.com/koajs/path-match","commit_stats":{"total_commits":116,"total_committers":9,"mean_commits":12.88888888888889,"dds":0.5,"last_synced_commit":"8ba2a7f132dc081a820ec681b12b7cd50e5a544e"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fpath-match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fpath-match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fpath-match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fpath-match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/path-match/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252212225,"owners_count":21712561,"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-08-03T18:01:08.983Z","updated_at":"2025-05-07T06:05:17.507Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"\n# Koa Path Match\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/koajs/path-match/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/koajs/path-match/actions?query=workflow%3A%22Node.js+CI%22)\n[![Test coverage][codecov-image]][codecov-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\nA simple routing wrapper around [path-match](https://github.com/expressjs/path-match).\nSimilar to [koa-route](https://github.com/koajs/route), except it optionally handles methods better.\nAll of these routers use [path-to-regexp](https://github.com/component/path-to-regexp)\nunderneath, which is what Express uses as well.\n\n```js\nconst route = require('koa-path-match')({/* options passed to path-to-regexp */})\n\napp.use(route('/:id', (ctx, next) =\u003e {\n  const id = ctx.params.id\n\n  // do stuff\n  switch (ctx.request.method) {\n\n  }\n}))\n```\n\nOr you can create middleware per method:\n\n```js\napp.use(route('/:id')\n  .get(async ctx =\u003e {\n    ctx.body = await Things.getById(ctx.params.id)\n  })\n  .delete(async ctx =\u003e {\n    await Things.delete(ctx.params.id)\n    ctx.status = 204\n  })\n)\n```\n\n## Maintainer\n\n- Lead: @jonathanong [@jongleberry](https://twitter.com/jongleberry)\n- Team: @koajs/routing\n\n## API\n\n### route(path, fns...)\n\n`path`s are just like Express routes. `fns` is either a single middleware\nor nested arrays of middleware, just like Express.\n\n### const router = route(path)\n\nWhen you don't set `fns` in the `route()` function, a router instance is returned.\n\n### router\\[method\\]\\(fns...\\)\n\nDefine a middleware just for a specific method.\n\n```js\napp.use(route('/:id').get(async ctx =\u003e {\n  ctx.body = await Things.getById(ctx.params.id)\n}))\n```\n\n- `next` is not passed as a parameter.\n  I consider this an anti-pattern in Koa - one route/method, one function.\n\n### this.params\n\nAny keys defined in the path will be set to `ctx.params`,\noverwriting any already existing keys defined.\n\n[npm-image]: https://img.shields.io/npm/v/koa-path-match.svg?style=flat\n[npm-url]: https://npmjs.org/package/koa-path-match\n[codecov-image]: https://img.shields.io/codecov/c/github/koajs/path-match/master.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/koajs/path-match\n[license-image]: http://img.shields.io/npm/l/koa-path-match.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/koa-path-match.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/koa-path-match\n","funding_links":[],"categories":["Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fpath-match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fpath-match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fpath-match/lists"}