{"id":13630445,"url":"https://github.com/amio/micro-fork","last_synced_at":"2025-07-30T21:33:26.756Z","repository":{"id":32761544,"uuid":"135128916","full_name":"amio/micro-fork","owner":"amio","description":"Fast and functional router","archived":false,"fork":false,"pushed_at":"2023-02-21T21:57:14.000Z","size":404,"stargazers_count":96,"open_issues_count":6,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-24T00:48:39.648Z","etag":null,"topics":["micro","router","zeit"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amio.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":"2018-05-28T07:59:40.000Z","updated_at":"2024-09-21T17:29:42.000Z","dependencies_parsed_at":"2024-01-05T23:50:26.493Z","dependency_job_id":"aa5f96d4-d5dc-4be5-9cbd-648bc24a93ae","html_url":"https://github.com/amio/micro-fork","commit_stats":{"total_commits":89,"total_committers":7,"mean_commits":"12.714285714285714","dds":0.6741573033707865,"last_synced_commit":"db3b8d864c863ebadc8ca2f64ad659e93c9172b1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/amio/micro-fork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amio%2Fmicro-fork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amio%2Fmicro-fork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amio%2Fmicro-fork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amio%2Fmicro-fork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amio","download_url":"https://codeload.github.com/amio/micro-fork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amio%2Fmicro-fork/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267314054,"owners_count":24067803,"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-07-27T02:00:11.917Z","response_time":82,"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":["micro","router","zeit"],"created_at":"2024-08-01T22:01:43.127Z","updated_at":"2025-07-30T21:33:26.703Z","avatar_url":"https://github.com/amio.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Modules"],"sub_categories":["Routing"],"readme":"\u003ch1 align=\"center\"\u003e\u003cimg height=\"80\" src=\"micro-fork.svg\" /\u003e\u003cbr /\u003emicro-fork\u003c/h1\u003e\n\n[![npm-badge]][npm-link]\n[![size-badge]][size-link]\n\nA fast and functional router for ZEIT's [Micro](https://github.com/zeit/micro).\nInspired by [microrouter](https://github.com/pedronauck/micro-router),\nuse [find-my-way](https://github.com/delvedor/find-my-way) underneath.\n\n## Features\n\n* **Tiny**. Just couple lines of code.\n* **Functional**. Write your http methods using functions.\n* **Async**. Design to use with `async/await`\n\n## Usage\n\nInstall as project dependency:\n\n```bash\n$ npm install micro-fork\n```\n\nThen you can define your routes inside your microservice:\n\n```js\nconst { send } = require('micro')\nconst { router, get } = require('micro-fork')\n\nconst hello = (req, res) =\u003e send(res, 200, `Hello ${req.params.who}`)\nconst notfound = (req, res) =\u003e send(res, 404, 'Not found route')\n\nmodule.exports = router()(\n  get('/hello/:who', hello),\n  get('/*', notfound)\n)\n```\n\n### `async/await`\n\nYou can use your handler as an async function:\n\n```js\nconst { send } = require('micro')\nconst { router, get } = require('micro-fork')\n\nconst hello = async (req, res) =\u003e\n  send(res, 200, await Promise.resolve(`Hello ${req.params.who}`))\n\nmodule.exports = router()(\n  get('/hello/:who', hello)\n)\n```\n\n### router\n\nInitialize a router:\n\n```javascript\nrouter(options)(\n  routeMethodA,\n  routeMethodB,\n  // ...\n)\n```\n\nThe `options` will directly goes to [find-my-way](https://github.com/delvedor/find-my-way#findmywayoptions)\n\n\n### route methods\n\nEach route is a single basic http method that you import from `micro-fork` and has the same arguments:\n\n* `get(path = String, handler = Function, [store = Object])`\n* `post(path = String, handler = Function, [store = Object])`\n* `put(path = String, handler = Function, [store = Object])`\n* `patch(path = String, handler = Function, [store = Object])`\n* `del(path = String, handler = Function, [store = Object])`\n* `head(path = String, handler = Function, [store = Object])`\n* `options(path = String, handler = Function, [store = Object])`\n\n#### path\n\nA simple url pattern that you can define your path. In this path you can set your parameters using a `:` notation. The `req` parameter from `handler` will return this parameters as an object.\n\nFor more information about how you can define your path, see [find-my-way](https://github.com/snd/url-pattern) that's the package that we're using to match paths.\n\n#### handler\n\nThe `handler` method is a simple function that will make some action base on your path.\nThe format of this function is `(req, res, store) =\u003e {}`\n\n##### `req.params`\n\nAs you can see below, the `req.params` parameter represents the parameters defined in your `path`:\n\n```js\n// service.js\nconst { send } = require('micro')\nconst { router, get } = require('micro-fork')\n\nmodule.exports = router()(\n  get('/hello/:who', (req, res) =\u003e send(req.params))\n)\n\n// test.js\nconst request = require('some-request-lib')\nconst response = await request('/hello/World')\n\nconsole.log(response)  // { who: 'World' }\n```\n\n##### `req.query`\n\n`req.query` represents parsed query parameters:\n\n```js\n// service.js\nconst { send } = require('micro')\nconst { router, get } = require('micro-fork')\n\nmodule.exports = router()(\n  get('/hello', (req, res) =\u003e send(req.query))\n)\n\n// test.js\nconst request = require('some-request-lib')\nconst response = await request('/hello?from=john')\n\nconsole.log(response)  // { from: 'john' }\n```\n\n#### `store`\n\nLast argument, `store` is used to pass an object that you can access later inside the handler function. If needed, store can be updated.\n\n### Parsing Body\n\nBy default, router _doens't parse anything_ from your requisition, it's just match your paths and execute a specific handler. So, if you want to parse your body requisition you can do something like that:\n\n```js\n// service.js\nconst { router, post } = require('micro-fork')\nconst { json, send } = require('micro')\n\nconst user = async (req, res) =\u003e {\n  const body = await json(req)\n  send(res, 200, body)\n}\n\nmodule.exports = router()(\n  post('/user', user)\n)\n\n// test.js\nconst request = require('some-request-lib')\n\nconst body = { id: 1 }\nconst response = await request.post('/user', { body })\n```\n\n## License\n\nISC @ Amio\n\n[amio-link]: https://github.com/amio\n[npm-badge]: https://flat.badgen.net/npm/v/micro-fork\n[npm-link]: https://www.npmjs.com/package/micro-fork\n[size-badge]: https://flat.badgen.net/bundlephobia/minzip/micro-fork\n[size-link]: https://bundlephobia.com/result?p=micro-fork\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famio%2Fmicro-fork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famio%2Fmicro-fork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famio%2Fmicro-fork/lists"}