{"id":26844960,"url":"https://github.com/moigagoo/kraut","last_synced_at":"2025-04-30T20:24:05.045Z","repository":{"id":79247948,"uuid":"605755992","full_name":"moigagoo/kraut","owner":"moigagoo","description":"Router for Karax frontend framework.","archived":false,"fork":false,"pushed_at":"2024-07-21T18:48:51.000Z","size":132,"stargazers_count":31,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-25T16:00:18.137Z","etag":null,"topics":["frontend","karax","nim","router","spa"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/moigagoo.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-23T20:45:46.000Z","updated_at":"2025-01-24T23:01:34.000Z","dependencies_parsed_at":"2024-07-14T08:47:42.645Z","dependency_job_id":null,"html_url":"https://github.com/moigagoo/kraut","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fkraut","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fkraut/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fkraut/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fkraut/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moigagoo","download_url":"https://codeload.github.com/moigagoo/kraut/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251775946,"owners_count":21641914,"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":["frontend","karax","nim","router","spa"],"created_at":"2025-03-30T19:33:55.585Z","updated_at":"2025-04-30T20:24:04.985Z","avatar_url":"https://github.com/moigagoo.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kraut\n\n**Kraut** is a router for [Karax](https://github.com/karaxnim/karax) frontend framework.\n\nKraut is best served with [Sauer](https://github.com/moigagoo/sauer) 👨‍🍳\n\n## Installation\n\nInstall Kraut with nimble:\n\n```\n$ nimble install kraut\n```\n\nAdd it to your .nimble file:\n\n```nim\nrequire \"kraut \u003e= 1.0.0\"\n```\n\nKraut doesn't have any dependencies outside stdlib except for Karax (duh).\n\n\n## Usage\n\nFirst, define your routes as an array or sequence of pattern-renderer pairs.\n\n**Pattern** is a string that Kraut uses to match against the hash part of the URI.\n\n**Renderer** is proc that takes a single argument of type `Context` and returns a `VNode`.\n\n**Context** is an object that holds the URL params extracted from the hash part in its `urlParams` field and the query params in `qryParams`.\n\nNim offers nice syntax to define Kraut routes:\n\n```nim\n# app.nim\n\nconst routes = {\n  \"/\": index.render,\n  \"/users/\": users.render,\n  \"/users/{userId}/\": user.render\n}\n```\n\nIn this example, `\"/users/{userId}\"` is a pattern and `user.render` us a renderer.\n\nYou can split your routes into groups for maintainability and even store the groups in different modules:\n\n```nim\nconst\n  indexRoute = @{\"/\": index.render}\n  userRoutes = @{\"/users/\": users.render, \"/users/{userId}/\": user.render}\n  routes = indexRoute \u0026 userRoutes\n```\n\nNext, define your renderers:\n\n```nim\n# user.nim\nimport kraut\n\nproc render*(context: Context): VNode =\n  buildHtml(tdiv):\n    text \"User id: \" \u0026 context.urlParams[\"userId\"]\n```\n\nFinally, generate the route renderer proc. It's a proc that accepts a single `RouterData` argument and returns a `VNode`. It can be passed directly to Karax's `setRenderer` proc or used inside another proc:\n\n```nim\n# app.nim\nimport kraut\n\nlet renderer = routerRenderer(routes)\n\nproc render(routerData: RouterData): VNode = \n  buildHtml(tdiv):\n    h1: text \"Header\"\n\n    renderer(routerData)\n\nsetRenderer(render)\n```\n\nSee the complete example in the `demo` folder.\n\n\n# Why you should use Kraut\n\n1. Route definition is dead simple.\n2. You can split your definitions and store them in separate modules.\n3. Renderer proc doesn't have to be anything special, it's just a regular proc you would use in Karax without Kraut, sans the `Context` argument.\n4. Kraut is efficient. No heavy regexes or hash maps, just iteration and string comparison that stops with the first match.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fkraut","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoigagoo%2Fkraut","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fkraut/lists"}