11#+TITLE: zig-curl
22#+DATE: 2023-09-16T23:16:15+0800
3- #+LASTMOD: 2025-10-02T10:13:24 +0800
3+ #+LASTMOD: 2025-10-03T12:35:20 +0800
44#+OPTIONS: toc:nil num:nil
55#+STARTUP: content
66
77[[https://img.shields.io/badge/zig%20version-0.15.1-blue.svg]]
8- [[https://img.shields.io/badge/zig%20version-master-blue.svg]]
98[[https://github.com/jiacai2050/zig-curl/actions/workflows/CI.yml][https://github.com/jiacai2050/zig-curl/actions/workflows/CI.yml/badge.svg]]
109[[https://ci.codeberg.org/repos/13257][https://ci.codeberg.org/api/badges/13257/status.svg]]
1110
1211Zig bindings for [[https://curl.haxx.se/libcurl/][libcurl]], a free and easy-to-use client-side URL transfer library.
1312
13+ #+ATTR_HTML: :width 30%
14+ [[file:docs/logo.svg]]
15+
1416The vendored libraries consist of:
1517| Library | Version |
1618|---------+---------|
@@ -26,11 +28,7 @@ cat examples/basic.zig
2628#+RESULTS:
2729#+begin_src zig
2830const std = @import("std");
29- const println = @import("util.zig").println;
30- const mem = std.mem;
31- const Allocator = mem.Allocator;
3231const curl = @import("curl");
33- const Easy = curl.Easy;
3432
3533pub fn main() !void {
3634 var gpa: std.heap.DebugAllocator(.{}) = .init;
@@ -39,38 +37,35 @@ pub fn main() !void {
3937
4038 const ca_bundle = try curl.allocCABundle(allocator);
4139 defer ca_bundle.deinit();
42- const easy = try Easy.init(.{
40+ const easy = try curl. Easy.init(.{
4341 .ca_bundle = ca_bundle,
4442 });
4543 defer easy.deinit();
44+
4645 {
47- println ("GET without write context" );
46+ std.debug.print ("GET without body\n", .{} );
4847 const resp = try easy.fetch("https://httpbin.org/anything", .{});
49-
5048 std.debug.print("Status code: {d}\n", .{resp.status_code});
5149 }
5250
5351 {
54- println("GET with fixed buffer" );
52+ std.debug.print("\nGET with fixed buffer as body\n", .{} );
5553 var buffer: [1024]u8 = undefined;
5654 var writer = std.Io.Writer.fixed(&buffer);
57- const resp = try easy.fetch("https://httpbin.org/anything", .{
58- .writer = &writer,
59- });
60- std.debug.print("Status code: {d}\nBody: {s}\n", .{
61- resp.status_code,
62- writer.buffered(),
63- });
55+ const resp = try easy.fetch("https://httpbin.org/anything", .{ .writer = &writer });
56+ std.debug.print("Status code: {d}\nBody: {s}\n", .{ resp.status_code, writer.buffered() });
6457 }
6558}
6659#+end_src
6760
61+ Check [[file:examples]] for more examples.
6862
69- See [[file:examples/basic.zig]], [[file:examples/advanced.zig]] for more usage.
63+ * Documentation
64+ See https://jiacai2050.github.io/zig-curl/
7065
7166* Installation
7267#+begin_src bash
73- zig fetch --save=curl https://github.com/jiacai2050/zig-curl/archive/refs/tags/${TAG}.zip
68+ zig fetch --save=curl https://github.com/jiacai2050/zig-curl/archive/refs/tags/${TAG}.zip
7469#+end_src
7570
7671The latest tag can be found on [[https://github.com/jiacai2050/zig-curl/releases/][release page]].
0 commit comments