{"id":13344067,"url":"https://github.com/kwlum/wws-zig-kit","last_synced_at":"2025-03-12T06:31:10.158Z","repository":{"id":80800655,"uuid":"603667575","full_name":"kwlum/wws-zig-kit","owner":"kwlum","description":"A Zig wasm workers server kit.","archived":false,"fork":false,"pushed_at":"2023-03-02T04:36:45.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-24T16:50:36.191Z","etag":null,"topics":["wasm","webassembly","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/kwlum.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":"2023-02-19T07:57:22.000Z","updated_at":"2024-10-14T16:41:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"b896dbde-0cbc-43b5-b022-5ec647185beb","html_url":"https://github.com/kwlum/wws-zig-kit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwlum%2Fwws-zig-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwlum%2Fwws-zig-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwlum%2Fwws-zig-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwlum%2Fwws-zig-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwlum","download_url":"https://codeload.github.com/kwlum/wws-zig-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243171621,"owners_count":20247877,"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":["wasm","webassembly","zig"],"created_at":"2024-07-29T19:32:20.060Z","updated_at":"2025-03-12T06:31:10.149Z","avatar_url":"https://github.com/kwlum.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WWS kit in Zig\nAn experimental [WWS](https://github.com/vmware-labs/wasm-workers-server) kit written in zig.\n\n\n# Usage Examples\n\n## Hello World\n\n```zig\nconst std = @import(\"std\");\nconst kit = @import(\"wws-zig-kit\");\n\nfn handle(request: kit.Request, response: *kit.Response, _: *kit.Cache) !void {\n    try response.headers.put(\"content-type\", \"text/plain\");\n    try response.body.writeAll(\"Hello World!\");\n    response.status = std.http.Status.ok;\n}\n\npub fn main() !void {\n    const routes = [_]kit.Route{kit.Route.get(handle)};    \n    try kit.run(std.heap.c_allocator, 65535, null, \u0026routes);\n}\n```\n\n\n## Cache (Key/Value Store)\n\nex: [counter](examples/counter/src/main.zig)\n```zig\nfn handle(_: *void, request: kit.Request, response: *kit.Response, cache: *kit.Cache) !void {\n    const counter_str = cache.get(\"counter\") orelse \"0\";\n    const counter = std.fmt.parseInt(u32, counter_str, 10) catch 0;\n\n    var buf: [16]u8 = undefined;\n    const counter_buf = try std.fmt.bufPrint(\u0026buf, \"{d}\", .{counter + 1});\n    try cache.put(\"counter\", counter_buf);\n\n    try response.body.print(\"Counter: {d}\", .{counter});\n    response.status = std.http.Status.ok;\n}\n```\n\n\n## Dynamic routes\n\nex: [dynamic-routes](examples/dynamic-routes/src/main.zig)\n```zig\nfn handle(_: *void, request: kit.Request, response: *kit.Response, _: *kit.Cache) !void {    \n    if (request.params.get(\"id\")) |id| {\n        try response.body.print(\"Product Id: {s}\", .{id});\n    } else {\n        try response.body.writeAll(\"Product not found.\");\n    }\n\n    try response.headers.put(\"content-type\", \"text/plain\");\n    response.status = http.Status.ok;\n}\n```\n\n\n## Environment variables\n\n```zig\nfn handle(_: kit.Request, response: *kit.Response, _: *kit.Cache) !void {\n    response.status = std.http.Status.ok;\n\n    const msg = std.os.getenv(\"message\") orelse \"\";\n    try response.body.writeAll(msg);\n}\n```\n\n\n# Build and Run\nBuild the echo example, require zig-0.10.1 installed:\n\n    zig build \n\nRun WWS inside workers directory, require WWS installed.\n\n    wws www\n\nCall the http endpoint with:\n\n    curl -d \"Hello World!\" http://localhost:8080/echo","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwlum%2Fwws-zig-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwlum%2Fwws-zig-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwlum%2Fwws-zig-kit/lists"}