Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jiacai2050/zig-curl
Zig bindings for libcurl
https://github.com/jiacai2050/zig-curl
libcurl libcurl-binding libcurl-bindings zig zig-lib zig-package ziglang
Last synced: about 2 months ago
JSON representation
Zig bindings for libcurl
- Host: GitHub
- URL: https://github.com/jiacai2050/zig-curl
- Owner: jiacai2050
- License: mit
- Created: 2023-09-16T15:13:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-12T12:41:29.000Z (7 months ago)
- Last Synced: 2024-05-13T05:22:58.178Z (7 months ago)
- Topics: libcurl, libcurl-binding, libcurl-bindings, zig, zig-lib, zig-package, ziglang
- Language: Zig
- Homepage: https://jiacai2050.github.io/zig-curl/
- Size: 2.97 MB
- Stars: 47
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - jiacai2050/zig-curl
README
#+TITLE: zig-curl
#+DATE: 2023-09-16T23:16:15+0800
#+LASTMOD: 2024-08-08T19:49:59+0800
#+OPTIONS: toc:nil num:nil
#+STARTUP: content[[https://img.shields.io/badge/zig%20version-0.13.0-blue.svg]]
[[https://img.shields.io/badge/zig%20version-master-blue.svg]]
[[https://github.com/jiacai2050/zig-curl/actions/workflows/CI.yml][https://github.com/jiacai2050/zig-curl/actions/workflows/CI.yml/badge.svg]]
[[https://ci.codeberg.org/repos/13257][https://ci.codeberg.org/api/badges/13257/status.svg]]Zig bindings for [[https://curl.haxx.se/libcurl/][libcurl]], a free and easy-to-use client-side URL transfer library.
#+begin_quote
This package is in early stage, although the core functionality works right now, the API is still subject to changes.
#+end_quoteThe vendored libraries consist of:
| Library | Version |
|---------+---------|
| libcurl | [[https://github.com/curl/curl/tree/curl-8_8_0][8.8.0]] |
| zlib | [[https://github.com/madler/zlib/tree/v1.3.1][1.3.1]] |
| mbedtls | [[https://github.com/Mbed-TLS/mbedtls/tree/v3.6.0][3.6.0]] |* Usage
#+begin_src zig
const curl = @import("curl");pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer if (gpa.deinit() != .ok) @panic("leak");
const allocator = gpa.allocator();const easy = try curl.Easy.init(allocator, .{});
defer easy.deinit();const resp = try easy.get("http://httpbin.org/anything");
defer resp.deinit();std.debug.print("Status code: {d}\nBody: {s}\n", .{
resp.status_code,
resp.body.items,
});
}
#+end_src
See [[file:examples/basic.zig]], [[file:examples/advanced.zig]] for more usage.* Installation
#+begin_src bash
zig fetch --save=curl https://github.com/jiacai2050/zig-curl/archive/${COMMIT}.tar.gz
#+end_srcReplace ~${COMMIT}~ with a real one, then in your =build.zig=, import the module like this:
#+begin_src zig
const dep_curl = b.dependency("curl", .{});
exe.root_module.addImport("curl", dep_curl.module("curl"));
exe.linkLibC();
#+end_srcThis library will link to a vendored libcurl by default, you can disable it and link to system-wide with this
#+begin_src zig
const dep_curl = b.dependency("curl", .{ .link_vendor = false });
exe.linkSystemLibrary("curl");
exe.linkLibC();
#+end_src* License
[[file:LICENSE][MIT]]