{"id":13799571,"url":"https://github.com/blakeembrey/kroute","last_synced_at":"2025-05-06T22:55:02.082Z","repository":{"id":15104081,"uuid":"17830874","full_name":"blakeembrey/kroute","owner":"blakeembrey","description":"Modular Koa router middleware with Express-style routes and middleware mounting","archived":false,"fork":false,"pushed_at":"2017-09-06T09:36:35.000Z","size":21,"stargazers_count":15,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T22:54:48.994Z","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":"weavejester/cljfmt","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blakeembrey.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":"2014-03-17T14:33:26.000Z","updated_at":"2023-09-08T10:06:57.000Z","dependencies_parsed_at":"2022-08-30T11:31:57.316Z","dependency_job_id":null,"html_url":"https://github.com/blakeembrey/kroute","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fkroute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fkroute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fkroute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fkroute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blakeembrey","download_url":"https://codeload.github.com/blakeembrey/kroute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782479,"owners_count":21803382,"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-04T00:01:04.092Z","updated_at":"2025-05-06T22:55:02.062Z","avatar_url":"https://github.com/blakeembrey.png","language":"JavaScript","readme":"# Kroute\n\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][downloads-image]][downloads-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\nModular Koa router middleware with Express-style routes and middleware mounting.\n\n## Install\n\n```\nnpm install kroute --save\n```\n\n## Usage\n\nKroute exports a function which can be used to create router instances that work with Koa middleware.\n\n```js\nvar koa = require('koa')\nvar kroute = require('kroute')\n\nvar app = koa()\nvar router = kroute()\n\napp.use(router)\n```\n\n### Initialization\n\nA router can be initialized with default handlers based on a resourceful routing object.\n\n```js\nrouter({\n  use: authorizeUser(),\n  index: function* () {},\n  create: [function* () {}, function* () {}]\n})\n```\n\nActions are mapped as follows:\n\n```\nGET     /                 -\u003e  index\nGET     /new              -\u003e  new\nPOST    /                 -\u003e  create\nGET     /:id              -\u003e  show\nGET     /:id/edit         -\u003e  edit\nPUT     /:id              -\u003e  update\nDELETE  /:id              -\u003e  destroy\n```\n\nThe object can also contain a `use` property which is mounted before any routes.\n\n### Routes\n\nEvery router instance can used to attach request handlers.\n\n```js\nrouter.get('/user', function* () {})\n```\n\nOmitting the path name will ensure the handler is always executed when the method matches.\n\n```js\nrouter.post(function* () {})\n```\n\nEvery route method accepts multiple middleware handlers.\n\n```js\nrouter.delete(authorizeUser(), function* () {})\n```\n\n### All Methods\n\nEvery router provides a `.all` method for attaching request handlers to every method.\n\n```js\nrouter.all(function* () {})\n```\n\nIt accepts a path and multiple middleware like any other method.\n\n```js\nrouter.all('/', authorizeUser(), function* () {})\n```\n\n### Mounting Middleware\n\nEvery router comes with the ability to mount middleware and handlers.\n\n```js\nvar mount = kroute()\n\nrouter.use('/users', mount)\n```\n\nAs long as the middleware follows the Koa generator pattern, it can be mounted.\n\n```js\nrouter.use('/users', function* (next) {\n  console.log(this.url) //=\u003e \"/123\" -\u003e Stripped the route prefix.\n\n  yield next\n})\n```\n\nLike other methods, `.use` also accepts multiple request handlers and an optional path.\n\n```js\nrouter.use(authorizeUser(), function* () {})\n```\n\n### Params\n\nEvery path can be dynamic and use Express-style parameter notation.\n\n```js\nrouter.get('/:user', function* () {\n  console.log(this.params.user) //=\u003e \"123\"\n})\n```\n\nEvery match is stored in the params as an object.\n\n```js\nrouter.get('/:foo/:bar', function* () {\n  console.log(this.params) //=\u003e { foo: \"123\", bar: \"456\" }\n})\n```\n\nThe route can also be a regular expression.\n\n```js\nrouter.get(/^\\/blog\\/(\\d{4})-(\\d{2})-(\\d{2})\\/?$/i, function* (next) {\n  console.log(this.params) // =\u003e { 0: '2014', 1: '03', 2: '17' }\n})\n```\n\n### Chaining\n\nEvery method returns it's own instance, so routes can be chained together like Express.\n\n```js\nrouter\n  .get('/foo', function* () {})\n  .post('/bar', function* () {})\n```\n\n### Options\n\nEvery method accepts an options object as the last argument.\n\n```js\nrouter.get('/foo', function* () {}, { strict: true, sensitive: true })\n```\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/kroute.svg?style=flat\n[npm-url]: https://npmjs.org/package/kroute\n[downloads-image]: https://img.shields.io/npm/dm/kroute.svg?style=flat\n[downloads-url]: https://npmjs.org/package/kroute\n[travis-image]: https://img.shields.io/travis/blakeembrey/kroute.svg?style=flat\n[travis-url]: https://travis-ci.org/blakeembrey/kroute\n[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/kroute.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/blakeembrey/kroute?branch=master\n","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Fkroute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakeembrey%2Fkroute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Fkroute/lists"}