Skip to content
/ url Public

Zig URL package is a URI extension package

Notifications You must be signed in to change notification settings

zon-dev/url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url

The URL features extension package is written in Zig.

Usage.

Adding to build.zig

    const url = b.dependency("url", .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("url", url.module("url"));

Import it in your code:

const URL = @import("url");
    var url = URL.init(.{});
    const text = "http://example.com/path?query=1&query2=2";
    const result = url.parse(text) catch return;
    try testing.expectEqualStrings("http", result.scheme());
    try testing.expectEqualStrings(
        "example.com",
        result.host(),
    );
    try testing.expectEqualStrings(
        "/path",
        result.path(),
    );
    try testing.expectEqualStrings("query=1&query2=2", result.query());

    var querymap = result.queryMap();
    try testing.expectEqualStrings("1", querymap.get("query").?);
    try testing.expectEqualStrings("2", querymap.get("query2").?);

    if (querymap.get("query3") != null) {
        try testing.expect(false);
    }