https://github.com/weskoerber/kewpie
A simple query string parser for Zig.
https://github.com/weskoerber/kewpie
zig zig-package ziglang
Last synced: about 1 year ago
JSON representation
A simple query string parser for Zig.
- Host: GitHub
- URL: https://github.com/weskoerber/kewpie
- Owner: weskoerber
- License: mit
- Created: 2024-02-10T18:28:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-04T22:37:51.000Z (about 1 year ago)
- Last Synced: 2025-04-14T06:14:29.180Z (about 1 year ago)
- Topics: zig, zig-package, ziglang
- Language: Zig
- Homepage: https://weskoerber.github.io/kewpie/
- Size: 22.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/weskoerber/kewpie/actions/workflows/test.yaml)
[](https://github.com/weskoerber/kewpie/actions/workflows/docs.yaml)
# Kewpie
A simple query string parser for zig.
## Getting Started
### Prerequisites
- [Zig](https://ziglang.org/download) (`0.14.0` or newer)
- If using Zig `0.12` and `0.13`, use the [`zig-0.12`](https://github.com/weskoerber/kewpie/tree/zig-0.12) branch
### Installation
1. Add kewpie as a dependency in your project using Zig's package manager
```console
zig fetch --save git+https://github.com/weskoerber/kewpie.git#0.1.1
```
2. Add kewpie module to your `build.zig`
```zig
const kewpie = b.dependency("kewpie", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("kewpie", kewpie.module("kewpie"));
```
### Usage
- Parse entire query string into a hash map
```zig
const std = @import("std");
const kewpie = @import("kewpie");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer if (gpa.deinit() != .ok) @panic("leak");
const uri = try std.Uri.parse("https://example.com?hello=world");
const query_params = try kewpie.parse(gpa.allocator(), uri);
defer query_params.deinit();
if (query_params.get("hello")) |value| {
// `value` holds the value `world`
// ...
}
}
```
- Parse the query string into an iterator
```zig
const std = @import("std");
const kewpie = @import("kewpie");
pub fn main() !void {
const uri = try std.Uri.parse("https://example.com?hello=world");
var query_params = kewpie.iter(uri);
while (query_params.next()) |param| {
// `param` holds a QueryParam struct
// ...
}
}
```