Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weskoerber/kewpie
A simple query string parser for Zig.
https://github.com/weskoerber/kewpie
querystring zig ziglang
Last synced: 9 days 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 (10 months ago)
- Default Branch: main
- Last Pushed: 2024-05-20T01:38:26.000Z (7 months ago)
- Last Synced: 2024-05-20T02:31:03.866Z (7 months ago)
- Topics: querystring, zig, ziglang
- Language: Zig
- Homepage: https://weskoerber.github.io/kewpie/
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![test](https://github.com/weskoerber/kewpie/actions/workflows/test.yaml/badge.svg)](https://github.com/weskoerber/kewpie/actions/workflows/test.yaml)
[![docs](https://github.com/weskoerber/kewpie/actions/workflows/docs.yaml/badge.svg)](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.12.0` or newer)
### 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
// ...
}
}
```