{"id":15155507,"url":"https://github.com/expressjs/urlrouter","last_synced_at":"2025-10-19T07:31:32.804Z","repository":{"id":3648557,"uuid":"4716223","full_name":"expressjs/urlrouter","owner":"expressjs","description":"http url router, `connect` missing router middleware","archived":false,"fork":false,"pushed_at":"2013-12-16T15:53:20.000Z","size":259,"stargazers_count":60,"open_issues_count":5,"forks_count":13,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-01-29T10:23:24.665Z","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/expressjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2012-06-19T16:33:03.000Z","updated_at":"2024-07-10T03:59:49.000Z","dependencies_parsed_at":"2022-08-19T04:21:38.362Z","dependency_job_id":null,"html_url":"https://github.com/expressjs/urlrouter","commit_stats":null,"previous_names":["fengmk2/urlrouter"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Furlrouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Furlrouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Furlrouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Furlrouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expressjs","download_url":"https://codeload.github.com/expressjs/urlrouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237088486,"owners_count":19253565,"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-09-26T18:22:34.520Z","updated_at":"2025-10-19T07:31:32.792Z","avatar_url":"https://github.com/expressjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!CAUTION]\n\u003e **This repository is archived and no longer actively maintained.**\n\u003e\n\u003e We are no longer accepting issues, feature requests, or pull requests.\n\u003e For additional support or questions, please visit the [Express.js Discussions page](https://github.com/expressjs/express/discussions).\n\n\n# urlrouter [![Build Status](https://secure.travis-ci.org/fengmk2/urlrouter.png)](http://travis-ci.org/fengmk2/urlrouter) [![Coverage Status](https://coveralls.io/repos/fengmk2/urlrouter/badge.png)](https://coveralls.io/r/fengmk2/urlrouter) [![Dependency Status](https://gemnasium.com/fengmk2/urlrouter.png)](https://gemnasium.com/fengmk2/urlrouter)\n\n[![NPM](https://nodei.co/npm/urlrouter.png?downloads=true\u0026stars=true)](https://nodei.co/npm/urlrouter/)\n\n![logo](https://raw.github.com/fengmk2/urlrouter/master/logo.png)\n\n`http` url router.\n\n[connect](https://github.com/senchalabs/connect) missing router middleware.\n\nSupport [express](http://expressjs.com) format [routing](http://expressjs.com/guide.html#routing).\n\nSupport `connect` @1.8.x and @2.2.0+ .\n\n## Test connect version\n\n* 1.8.0+: 1.8.0 1.8.5 1.8.6 1.8.7\n* 1.9.0+\n* 2.2.0+\n* 2.3.0+\n* 2.4.0+\n* 2.7.0+\n* 2.8.0+\n\n```bash\n$ make test-all\n```\n\n## Install\n\n```bash\n$ npm install urlrouter\n```\n\n## Usage\n\n### Using with `connect`\n\n```js\nvar connect = require('connect');\nvar urlrouter = require('urlrouter');\n\nconnect(urlrouter(function (app) {\n  app.get('/', function (req, res, next) {\n    res.end('hello urlrouter');\n  });\n  app.get('/user/:id([0-9]+)', function (req, res, next) {\n    res.end('hello user ' + req.params.id);\n  });\n})).listen(3000);\n```\n\nSeveral callbacks may also be passed.\n\n```js\n\nfunction loadUser(req, res, next) {\n  // You would fetch user from the db\n  var user = users[req.params.id];\n  if (user) {\n    req.user = user;\n    next();\n  } else {\n    next(new Error('Failed to load user ' + req.params.id));\n  }\n}\n\napp.get('/user/:id', loadUser, function () {\n  // ...\n});\n```\n\nThese callbacks can be passed within arrays as well.\n\n```js\nvar middleware = [loadUser, loadForum, loadThread];\napp.post('/forum/:fid/thread/:tid', middleware, function () {\n // ...\n});\n```\n\n### Using with `http.createServer()`\n\n```js\nvar http = require('http');\nvar urlrouter = require('urlrouter');\n\nvar options = {\n  pageNotFound: function (req, res) {\n    res.statusCode = 404;\n    res.end('er... some page miss...');\n  },\n  errorHandler: function (req, res) {\n    res.statusCode = 500;\n    res.end('oops..error occurred');\n  }\n};\n\nfunction loadUser(req, res, next) {\n  // You would fetch user from the db\n  var user = users[req.params.id];\n  if (user) {\n    req.user = user;\n    next();\n  } else {\n    next(new Error('Failed to load user ' + req.params.id));\n  }\n}\n\nvar routerMiddleware = urlrouter(function (app) {\n  app.get('/', function (req, res) {\n    res.end('GET home page' + req.url + ' , headers: ' + JSON.stringify(req.headers));\n  });\n  // with route middleware\n  app.get('/user/:id', loadUser, function (req, res) {\n    res.end('user: ' + req.params.id);\n  });\n\n  // GET /admin 301 redirect to /admin/\n  app.redirect('/admin', '/admin/');\n\n  app.get(/^\\/users?(?:\\/(\\d+)(?:\\.\\.(\\d+))?)?/, loadUser, function (req, res) {\n    res.end(req.url + ' : ' + req.params);\n  });\n\n  app.get('/foo', function (req, res) {\n    res.end('GET ' + req.url + ' , headers: ' + JSON.stringify(req.headers));\n  });\n\n  app.post('/new', function (req, res) {\n    res.write('POST ' + req.url + ' start...\\n\\n');\n    var counter = 0;\n    req.on('data', function (data) {\n      counter++;\n      res.write('data' + counter + ': ' + data.toString() + '\\n\\n');\n    });\n    req.on('end', function () {\n      res.end('POST ' + req.url + ' end.\\n');\n    });\n  });\n\n  app.put('/update', function (req, res) {\n    res.end('PUT ' + req.url + ' , headers: ' + JSON.stringify(req.headers));\n  });\n\n  app.delete('/remove', function (req, res) {\n    res.end('DELETE ' + req.url + ' , headers: ' + JSON.stringify(req.headers));\n  });\n\n  app.options('/check', function (req, res) {\n    res.end('OPTIONS ' + req.url + ' , headers: ' + JSON.stringify(req.headers));\n  });\n\n  app.all('/all', function (req, res) {\n    res.end('ALL methods request /all should be handled' + ' , headers: ' + JSON.stringify(req.headers));\n  });\n}, options);\n\nhttp.createServer(routerMiddleware).listen(3000);\n```\n\n## Contributors\n\n```bash\n$ git summary\n\n project  : urlrouter\n repo age : 1 year, 1 month\n active   : 16 days\n commits  : 38\n files    : 19\n authors  :\n    33  fengmk2                 86.8%\n     4  rockdai                 10.5%\n     1  rock                    2.6%\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 - 2013 fengmk2 \u003cfengmk2@gmail.com\u003e.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Furlrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpressjs%2Furlrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Furlrouter/lists"}