Open giann opened 2 years ago
http + tls now available in zig std lib:
const std = @import("std");
pub fn main() !void {
var client = std.http.Client{
.allocator = std.heap.c_allocator,
};
try client.ca_bundle.addCertsFromFile(
client.allocator,
std.fs.cwd(),
"root.cer",
);
var request = try client.request(
try std.Uri.parse("https://www.boredapi.com/api/activity"),
.{},
.{},
);
var buffer = [_]u8{0} ** 1024;
_ = try request.readAll(&buffer);
std.debug.print("Read:\n{s}\n", .{buffer});
}
Will fetch trusted certificates on its own only on linux. macOS is maybe harder since certificates are in the keychain.
Certificate are fetched since https://github.com/ziglang/zig/pull/14325