Zig
Zig
Parse a URL into its Component Parts
See more HTTP Examples
Demonstrates how to parse a URL into it's component parts.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const url = try chilkat.Url.init();
defer url.deinit();
var url_str: [:0]const u8 = "https://www.amazon.com/Anarchy-State-Utopia-Robert-Nozick/dp/0465051006/ref=sr_1_1?s=books&ie=UTF8&qid=1430344305&sr=1-1&keywords=nozick#frag123";
try url.parseUrl(url_str);
// Assume success..
std.debug.print("URL: {s}\n", .{url_str});
std.debug.print("Host: {s}\n", .{try url.getHost(alloc)});
std.debug.print("Port: {d}\n", .{url.getPort()});
std.debug.print("HostType: {s}\n", .{try url.getHostType(alloc)});
std.debug.print("Ssl: {}\n", .{url.getSsl()});
std.debug.print("Path: {s}\n", .{try url.getPath(alloc)});
std.debug.print("Query: {s}\n", .{try url.getQuery(alloc)});
std.debug.print("Frag: {s}\n", .{try url.getFrag(alloc)});
std.debug.print("----\n", .{});
url_str = "http://matt:secret@www.chilkatsoft.com:8080/somepath.asp?test=123&size=2";
try url.parseUrl(url_str);
// Assume success..
std.debug.print("URL: {s}\n", .{url_str});
std.debug.print("Host: {s}\n", .{try url.getHost(alloc)});
std.debug.print("Port: {d}\n", .{url.getPort()});
std.debug.print("HostType: {s}\n", .{try url.getHostType(alloc)});
std.debug.print("Ssl: {}\n", .{url.getSsl()});
std.debug.print("Login: {s}\n", .{try url.getLogin(alloc)});
std.debug.print("Password: {s}\n", .{try url.getPassword(alloc)});
std.debug.print("Path: {s}\n", .{try url.getPath(alloc)});
std.debug.print("Query: {s}\n", .{try url.getQuery(alloc)});
std.debug.print("Frag: {s}\n", .{try url.getFrag(alloc)});
}