{"id":21173922,"url":"https://github.com/zigzedd/zouter","last_synced_at":"2025-09-11T05:41:36.438Z","repository":{"id":258590780,"uuid":"870906163","full_name":"zigzedd/zouter","owner":"zigzedd","description":"[MIRROR] Zig HTTP router library.","archived":false,"fork":false,"pushed_at":"2025-04-11T22:15:37.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T22:35:20.251Z","etag":null,"topics":["router","routing","routing-engine","zap","zig","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"https://code.zeptotech.net/zedd/zouter","language":"Zig","has_issues":false,"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/zigzedd.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-10T22:11:55.000Z","updated_at":"2025-04-11T21:41:06.000Z","dependencies_parsed_at":"2024-10-21T13:51:33.224Z","dependency_job_id":null,"html_url":"https://github.com/zigzedd/zouter","commit_stats":null,"previous_names":["zigzedd/zouter"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zigzedd/zouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zigzedd","download_url":"https://codeload.github.com/zigzedd/zouter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzouter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270852229,"owners_count":24656842,"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-17T02:00:09.016Z","response_time":129,"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":["router","routing","routing-engine","zap","zig","zig-library","zig-package"],"created_at":"2024-11-20T16:52:45.547Z","updated_at":"2025-08-17T13:15:02.363Z","avatar_url":"https://github.com/zigzedd.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://code.zeptotech.net/zedd/zouter\"\u003e\n\t\t\u003cpicture\u003e\n\t\t\t\u003cimg alt=\"Zouter logo\" width=\"150\" src=\"https://code.zeptotech.net/zedd/zouter/raw/branch/main/logo.svg\" /\u003e\n\t\t\u003c/picture\u003e\n\t\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n\tZouter\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003e\n\t\u003ca href=\"https://code.zeptotech.net/zedd/zouter\"\u003eDocumentation\u003c/a\u003e\n|\n\t\u003ca href=\"https://zedd.zeptotech.net/zouter/api\"\u003eAPI\u003c/a\u003e\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n\tZig HTTP router library\n\u003c/p\u003e\n\nZouter is part of [_zedd_](https://code.zeptotech.net/zedd), a collection of useful libraries for zig.\n\n## Zouter for zap\n\n_Zouter_ is an HTTP router library for Zig **zap** HTTP server. It's made to ease the use of **zap** to build REST APIs.\n\n## Versions\n\nZouter 0.2.0 is made for zig 0.14.0 and tested with zap 0.10.1.\n\n## How to use\n\n### Install\n\nIn your project directory:\n\n```shell\n$ zig fetch --save https://code.zeptotech.net/zedd/zouter/archive/v0.2.0.tar.gz\n```\n\nIn `build.zig`:\n\n```zig\n// Add zouter dependency.\nconst zouter = b.dependency(\"zouter\", .{\n\t.target = target,\n\t.optimize = optimize,\n});\nexe.root_module.addImport(\"zouter\", zouter.module(\"zouter\"));\n```\n\n### Example\n\nHere is a quick example of how to set up a router. It is an extract from the full test code at [`example.zig`](https://code.zeptotech.net/zedd/zouter/src/branch/main/tests/example.zig). You may want to have a look to [`simple_routes.zig`](https://code.zeptotech.net/zedd/zouter/src/branch/main/tests/simple_routes.zig) which shows more advanced features.\n\n```zig\n/// GET /foo/:arg/bar request handler.\nfn get(route: zouter.MatchedRoute, request: zap.Request) !void {\n\tvar bodyBuffer: [512]u8 = undefined;\n\tconst body = try std.fmt.bufPrint(\u0026bodyBuffer, \"get: {s}\", .{route.params.get(\"arg\").?});\n\ttry request.sendBody(body);\n}\n\n/// POST /foo/:arg/bar request handler.\nfn post(route: zouter.MatchedRoute, request: zap.Request) !void {\n\tvar bodyBuffer: [512]u8 = undefined;\n\tconst body = try std.fmt.bufPrint(\u0026bodyBuffer, \"post: {s}\", .{route.params.get(\"arg\").?});\n\ttry request.sendBody(body);\n}\n\n/// Setup an example router.\nfn setupExampleRouter(allocator: std.mem.Allocator) !zouter.Router {\n\t// Initialize an example router.\n\tvar exampleRouter = try zouter.Router.init(allocator, .{});\n\n\t// Add a route to the example router.\n\ttry exampleRouter.route(.{\n\t\t.path = \"foo\",\n\t\t.children = \u0026[_]zouter.RouteDefinition{\n\t\t\t.{\n\t\t\t\t.path = \":arg\",\n\t\t\t\t.children = \u0026[_]zouter.RouteDefinition{\n\t\t\t\t\t.{\n\t\t\t\t\t\t.path = \"bar\",\n\t\t\t\t\t\t.handle = .{\n\t\t\t\t\t\t\t.get = \u0026get,\n\t\t\t\t\t\t\t.post = \u0026post,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t});\n\n\treturn exampleRouter;\n}\n```\n\n### Route definition\n\nA route only has one mandatory field: its path. If any part of a path starts with a `':'`, the value is taken as a dynamic variable, retrievable later with `Route.params` `HashMap`.\n\nA route can have:\n\n- **Children**: sub-routes definitions, with a `'/'` between the parent and the child. It's useful to prefix a list of routes with the same path / variable.\n- **Handle object**: you can define a handle function for each HTTP basic request method. If you don't care about the request method, there is an `any` field which will be used for all undefined request methods.\n- **Handle not found / error**: you can define a custom functions to handle errors or not found pages inside this path.\n- **Pre-handle / post-handle**: these functions are started before and after the request handling in this path. It looks like middlewares and can assume the same role as most of them (e.g. a pre-handle function to check for authentication under a specific path).\n\nFull details about route definition fields can be found in the [API reference](https://zedd.zeptotech.net/zouter/api).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzedd%2Fzouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzigzedd%2Fzouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzedd%2Fzouter/lists"}