{"id":13716085,"url":"https://github.com/Synvox/router","last_synced_at":"2025-05-07T05:32:08.203Z","repository":{"id":34735409,"uuid":"182345996","full_name":"Synvox/router","owner":"Synvox","description":"A tiny routing library to complement micro inspired by the good and bad parts of express.js.","archived":true,"fork":false,"pushed_at":"2023-02-28T15:21:38.000Z","size":1079,"stargazers_count":8,"open_issues_count":19,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T00:14:10.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Synvox.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}},"created_at":"2019-04-20T01:38:06.000Z","updated_at":"2024-10-23T00:38:40.000Z","dependencies_parsed_at":"2024-01-16T12:01:25.289Z","dependency_job_id":null,"html_url":"https://github.com/Synvox/router","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":"0.11428571428571432","last_synced_commit":"96ae1de7413086d6abb381f08d481ac2c8eec2ad"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Synvox%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Synvox%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Synvox%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Synvox%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Synvox","download_url":"https://codeload.github.com/Synvox/router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823131,"owners_count":21809700,"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-03T00:01:06.897Z","updated_at":"2025-05-07T05:32:06.720Z","avatar_url":"https://github.com/Synvox.png","language":"JavaScript","funding_links":[],"categories":["Modules"],"sub_categories":["Routing"],"readme":"# `@synvox/router`\n\n[![travis ci](https://img.shields.io/travis/Synvox/router.svg)](https://travis-ci.org/Synvox/router)\n[![codecov](https://codecov.io/gh/Synvox/router/branch/master/graph/badge.svg)](https://codecov.io/gh/Synvox/router)\n\nA tiny routing library to complement [micro](https://github.com/zeit/micro) inspired by the good and bad parts of `express.js`.\n\n## Example\n\n```js\nimport micro from \"micro\";\nimport Router from \"@synvox/router\";\n\nconst app = Router();\n\napp.get(\"/\", (_req, _res) =\u003e \"Hello World!\");\n\nmicro(app).listen(3000);\n```\n\n`@synvox/router` is different than other `micro` routers because it enables nesting. This is very nice when you are combining routers together:\n\n```js\nimport micro from \"micro\";\nimport Router from \"@synvox/router\";\n\nimport AuthService from \"./auth\";\nimport PeopleService from \"./people\";\n\nconst app = Router();\n\napp.use(\"/auth\", AuthService);\napp.use(\"/people\", PeopleService);\n\nmicro(app).listen(3000);\n```\n\nThere is no `next` method and middleware is discouraged. _In `synvox/router`, the req object is a vanilla `http.IncomingMessage` object._ There is no `req.body`, `req.params`, `req.query`, etc. Instead try this:\n\n```js\nimport micro from \"micro\";\nimport Router, { params, query } from \"@synvox/router\";\n\nconst app = Router();\n\napp.get(\"/:name\", req =\u003e {\n  const { name } = params(req);\n  const { sort } = query(req);\n  // do something with `name` and `sort`\n  return { ok: true };\n});\n\nmicro(app).listen(3000);\n```\n\nYou may also write your own hooks using `createHook`:\n\n```js\nimport micro from \"micro\";\nimport Router, { params, body, createHook } from \"@synvox/router\";\n\nconst useUser = createHook(async req =\u003e {\n  const token = req.headers.token;\n  const user = token ? await Users.get(token) : null;\n\n  return user;\n});\n\nconst app = Router();\n\napp.get(\"/\", async req =\u003e {\n  const user = await useUser(req);\n  // do something with `user`\n  return { ok: true };\n});\n\nmicro(app).listen(3000);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSynvox%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSynvox%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSynvox%2Frouter/lists"}