{"id":16132638,"url":"https://github.com/sbrl/powahroot","last_synced_at":"2025-03-18T15:30:28.788Z","repository":{"id":40575065,"uuid":"183703082","full_name":"sbrl/powahroot","owner":"sbrl","description":"Client and server-side routing micro frameworks","archived":false,"fork":false,"pushed_at":"2024-09-12T16:05:15.000Z","size":1618,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-10T22:31:45.415Z","etag":null,"topics":["client-side","library","npm-module","npm-package","routing-engine","server-side"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbrl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":"FUNDING.yml","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},"funding":{"liberapay":"sbrl"}},"created_at":"2019-04-26T22:52:54.000Z","updated_at":"2024-09-12T16:05:20.000Z","dependencies_parsed_at":"2024-06-05T13:11:37.820Z","dependency_job_id":"e9fe8e2a-64a3-464e-acdf-12ea35cab32b","html_url":"https://github.com/sbrl/powahroot","commit_stats":{"total_commits":71,"total_committers":2,"mean_commits":35.5,"dds":0.09859154929577463,"last_synced_commit":"1f75b188062496f0f4c5ac8b88e544e23c47d063"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fpowahroot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fpowahroot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fpowahroot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fpowahroot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbrl","download_url":"https://codeload.github.com/sbrl/powahroot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221713368,"owners_count":16868247,"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":["client-side","library","npm-module","npm-package","routing-engine","server-side"],"created_at":"2024-10-09T22:32:03.168Z","updated_at":"2024-10-27T17:52:53.002Z","avatar_url":"https://github.com/sbrl.png","language":"JavaScript","funding_links":["https://liberapay.com/sbrl"],"categories":[],"sub_categories":[],"readme":"# ![](https://raw.githubusercontent.com/sbrl/powahroot/master/logo-large.png)powahroot\n\n\u003e Client and server-side routing micro frameworks\n\n_Powahroot_ is a pair of micro routing frameworks, presented as an ES6 module:\n\n - The first is for client-side single-page web applications\n - The other is for handling server-side Node.js requests\n\nIt's based on [`rill`](https://www.npmjs.com/package/rill) (see the npm package bearing the name), but stripped down and simplified.\n\n- **Current version:** ![current npm version - see the GitHub releases](https://img.shields.io/npm/v/powahroot)\n- **Changelog:** https://github.com/sbrl/powahroot/blob/main/CHANGELOG.md\n\n## Getting Started\nInstall powahroot as a dependency with npm:\n\n```bash\nnpm install --save powahroot\n```\n\nIf your build process supports [tree-shaking](https://webpack.js.org/guides/tree-shaking/), only the router(s?) you need will be included in the final output of your build - as _powahroot_ uses ES6 modules.\n\n\n## Usage\n\n### Paths\nPowahroot supports multiple syntax bells and whistles when defining routes. These are documented below:\n\nSyntax\t\t\t\t\t\t\t| Meaning\n--------------------------------|----------------------------------------\n`/index.html`\t\t\t\t\t| Regular route. Matches exactly what it says on the tin.\n`*`\t\t\t\t\t\t\t\t| Special key(word?) that matches _any_ route. Must be present on its own without any other characters.\n`/add/vegetable/:name/:weight`\t| Parameters. Match values an pull them into an object automatically. Does not like forward slashes in parameter values.\n`/images/::path`\t\t\t\t| Parameter values with forward slashes. If you want to use parameters, but need values to be able to contain forward slashes `/`, this is for you. Don't forget you can mix-and-match this with the previous example!\n\n### Client\nInitialise a new router like this:\n\n```js\nimport ClientRouter from 'powahroot/Client.mjs';\n\n// ....\n\nconst router = new ClientRouter({\n\t// Options object. Default settings:\n\tverbose: false, // Whether to be verbose in console.log() messages\n\tlisten_pushstate: true, // Whether to react to browser pushstate events (excluding those generated by powahroot itself, because that would cause an infinite loop :P)\n});\n\n// Add a page\nrouter.add_page(\"/add/vegetable/:name/:weight\", (params) =\u003e {\n    console.log(`We added a ${params.name} with a weight of ${params.weight}g.`);\n});\n\n// Explicitly navigate to a page:\nrouter.navigate(\"/add/carrot/frederick/10001\");\n```\n\n### Server\nThe server router works slightly differently, to account for the different environment it's designed for. Here's how to use it:\n\n```js\nimport ServerRouter from 'powahroot/Server.mjs';\n\n// ....\n\nconst router = new ServerRouter();\n// Logging middle ware\nrouter.on_all(async (context, next) =\u003e {\n    console.debug(context.url);\n    await next();\n});\n// Regular handlere\nrouter.get(\"/files/::filepath\", (context, _next) =\u003e context.send.plain(200, `You requested ${context.params.filepath}`));\n// .....\n\n// Later, when you've got a request / response pair to handle:\nawait router.handle(request, response);\n```\n\nThe `context` argument there is of type `RouterContext`. Check out the API reference (link below) to learn about the other useful properties it has.\n\n## Reference\nAPI docs are generated automatically. View them here:\n\n\u003chttps://starbeamrainbowlabs.com/code/powahroot/docs/\u003e\n\nIt contains full documentation on how to use everything, along with code examples to help you get started.\n\n## Contributing\nContributions are welcome! Simply fork this repository, make your changes, and submit a [Pull Request](https://help.github.com/en/articles/about-pull-requests) (issues are welcome too!).\n\nAll contributions must be declared to have the `Mozilla Public License 2.0` (the same license that this repository is under).\n\n## Licence\nEverything in this repository _except_ the logo is licenced under the _Mozilla Public License 2.0.\n\nThe logo itself is © Copyright Starbeamrainbowlabs 2019. All rights reserved - though you _may_ use it when linking to this project (or to advertise usage in a 'powered by' logo).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fpowahroot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbrl%2Fpowahroot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fpowahroot/lists"}