{"id":16208649,"url":"https://github.com/cloudef/zig-router","last_synced_at":"2025-03-19T08:30:49.105Z","repository":{"id":213377830,"uuid":"734001718","full_name":"Cloudef/zig-router","owner":"Cloudef","description":"Straightforward HTTP-like request routing.","archived":false,"fork":false,"pushed_at":"2025-03-10T08:46:52.000Z","size":33,"stargazers_count":26,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-10T09:43:46.312Z","etag":null,"topics":["backend","http","routing","web-framework","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/Cloudef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/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":{"github":["Cloudef"]}},"created_at":"2023-12-20T16:17:51.000Z","updated_at":"2025-03-10T08:46:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"7be3cc7b-473f-4645-8e8e-ac2cc1131008","html_url":"https://github.com/Cloudef/zig-router","commit_stats":null,"previous_names":["cloudef/zig-router"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cloudef%2Fzig-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cloudef%2Fzig-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cloudef%2Fzig-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cloudef%2Fzig-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cloudef","download_url":"https://codeload.github.com/Cloudef/zig-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976472,"owners_count":20377691,"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":["backend","http","routing","web-framework","zig"],"created_at":"2024-10-10T10:25:07.628Z","updated_at":"2025-03-19T08:30:49.100Z","avatar_url":"https://github.com/Cloudef.png","language":"Zig","readme":"# zig-router\n\nStraightforward HTTP-like request routing.\n\n---\n\nProject is tested against zig 0.13.0\n\n## Sample\n\n```zig\nconst router = @import(\"zig-router\");\n\nconst MyJsonBody = struct {\n    float: f32,\n    text: []const u8,\n    number_with_default: u32 = 42,\n};\n\nfn putJson(body: MyJsonBody) !Response {\n    log.info(\"float: {}\", .{body.float});\n    log.info(\"text: {s}\", .{body.text});\n    log.info(\"number_with_default: {}\", .{body.number_with_default});\n    return .{ .body = \"ok\" };\n}\n\nconst MyPathParams = struct {\n    id: []const u8,\n    bundle: u32,\n};\n\nfn getDynamic(params: MyPathParams) !Response {\n    log.info(\"id: {s}\", .{params.id});\n    log.info(\"bundle: {}\", .{params.bundle});\n    return .{};\n}\n\nconst MyQuery = struct {\n    id: []const u8 = \"plz give me a good paying stable job\",\n    bundle: u32 = 42,\n};\n\nfn getQuery(query: MyQuery) !Response {\n    log.info(\"id: {s}\", .{query.id});\n    log.info(\"bundle: {}\", .{query.bundle});\n    return .{};\n}\n\nfn getError() !void {\n    return error.EPIC_FAIL;\n}\n\nfn onRequest(arena: *std.heap.ArenaAllocator, request: Request) !void {\n    router.Router(.{\n        router.Decoder(.json, router.JsonBodyDecoder(.{}, 4096).decode),\n    }, .{\n        router.Route(.PUT, \"/json\", putJson, .{}),\n        router.Route(.GET, \"/dynamic/:id/paths/:bundle\", getDynamic, .{}),\n        router.Route(.GET, \"/query\", getQuery, .{}),\n        router.Route(.GET, \"/error\", getError, .{}),\n    }).match(arena.allocator(), .{\n        .method = request.method,\n        .path = request.path,\n        .query = request.query,\n        .body = .{ .reader = request.body.reader() }\n    }, .{ arena.allocator() }) catch |err| switch (err) {\n        error.not_found =\u003e return .{ .status = .not_found },\n        error.bad_request =\u003e return .{ .status = .bad_request },\n        else =\u003e return err,\n    };\n}\n```\n\n## Depend\n\nRun the following command in zig project root directory.\n\n```sh\nzig fetch --save git+https://github.com/Cloudef/zig-router.git\n```\n\nIn `build.zig` file add the following for whichever modules `zig-router` is required.\n\n```zig\nconst zig_router = b.dependency(\"zig-router\", .{});\nexe.root_module.addImport(\"zig-router\", zig_router.module(\"zig-router\"));\n```\n\nYou can now import the `zig-router` from zig code.\n\n```zig\nconst router = @import(\"zig-router\");\n```\n","funding_links":["https://github.com/sponsors/Cloudef"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudef%2Fzig-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudef%2Fzig-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudef%2Fzig-router/lists"}