{"id":30622457,"url":"https://github.com/zoomten/justarouter","last_synced_at":"2025-08-30T15:40:34.353Z","repository":{"id":304127028,"uuid":"1013273142","full_name":"ZoomTen/justarouter","owner":"ZoomTen","description":"Just a router for Nim.","archived":false,"fork":false,"pushed_at":"2025-07-31T04:09:48.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-31T07:35:01.674Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nim","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/ZoomTen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-07-03T16:17:03.000Z","updated_at":"2025-07-31T04:09:52.000Z","dependencies_parsed_at":"2025-07-11T11:12:27.233Z","dependency_job_id":null,"html_url":"https://github.com/ZoomTen/justarouter","commit_stats":null,"previous_names":["zoomten/justarouter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZoomTen/justarouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZoomTen%2Fjustarouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZoomTen%2Fjustarouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZoomTen%2Fjustarouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZoomTen%2Fjustarouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZoomTen","download_url":"https://codeload.github.com/ZoomTen/justarouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZoomTen%2Fjustarouter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272871255,"owners_count":25007133,"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-08-30T02:00:09.474Z","response_time":77,"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":[],"created_at":"2025-08-30T15:40:29.024Z","updated_at":"2025-08-30T15:40:34.347Z","avatar_url":"https://github.com/ZoomTen.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Just A Router\n\n## What\n\nExactly as it says on the tin:\n```nim\nimport justarouter\n\ntype ServerState = object\n  # this would be where parameters\n  # you want to pass to the router would be,\n  # if you had any.\n\nmakeRouter(\"routeThis\", ServerState, string):\n  get \"/\":\n    output = \"Welcome home!\"\n  \n  get \"/users/{id}/profile\":\n    let num = pathParams[\"id\"].parseInt()\n    if num == 10:\n      output = \"Name: avery\"\n    else:\n      output = \"Invalid user!\"\n  \n  post \"/upload\":\n    output = \"hey!\"\n  \n  default:\n    output = \"Not found...\"\n  \n  methodNotAllowed:\n    output = \"Method not allowed\"\n  \n  exceptionHandler:\n    debugEcho \"oops! \" \u0026 e.repr\n    output = \"Something went wrong\"\n\nwhen isMainModule:\n  let state = ServerState()\n  var reply = \"\"\n\n  # defined via makeRouter ^\n  routeThis(\"GET\", \"/\", state, reply)\n  assert reply == \"Welcome home!\"\n```\n\n## Why\n\nA lot of Nim web frameworks come bundled with an HTTP router.\nFor a project, I was using one that was quite barebones—not so much\na framework as it is a library. I didn't feel like ripping a router\nfrom another framework, but I *was* inspired by the one that\nJester has.\n\n## Implementation\n\n1. Scan the AST of the `makeRouter` call\n2. Separate out the static routes and dynamic routes\n3. Create the \"not found\" and \"method not allowed\" templates within the new proc\n4. Create a giant regex out of the collected dynamic routes\n5. Use the giant regex to implement dynamic route processing.\n6. Create a switch statement out of the collected static routes, and jumping into the dynamic route processing routine as a fallback.\n7. Produce the final proc, wrapping it in an exception handler if one exists.\n\n## Tips\n\n- Since the regex works in order, you may want to put the most-used dynamic route earlier in the route definition order, that way those routes will run a little faster.\n- The regex is generic, it can't be used to validate routes from the get-go.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoomten%2Fjustarouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoomten%2Fjustarouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoomten%2Fjustarouter/lists"}