• This repository has been archived on 18/Sep/2023
  • Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Zig
  • License
    BSD Zero Clause L...
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTTP client for Zig ðŸĶŽ

Requestz

An HTTP client inspired by httpx and ureq.

Build Status License Requirements

⚠ïļ I'm currently renovating an old house which does not allow me to work on requestz, h11 and http anymore. Feel free to fork or borrow some ideas if there are any good ones :)

Installation

requestz is available on astrolabe.pm via gyro

gyro add ducdetronquito/requestz

Usage

Send a GET request

const client = @import("requestz.zig").Client;

var client = try Client.init(std.testing.allocator);
defer client.deinit();

var response = try client.get("http://httpbin.org/get", .{});
defer response.deinit();

Send a request with headers

const Headers = @import("http").Headers;

var headers = Headers.init(std.testing.allocator);
defer headers.deinit();
try headers.append("Gotta-go", "Fast!");

var response = try client.get("http://httpbin.org/get", .{ .headers = headers.items() });
defer response.deinit();

Send a request with compile-time headers

var headers = .{
    .{"Gotta-go", "Fast!"}
};

var response = try client.get("http://httpbin.org/get", .{ .headers = headers });
defer response.deinit();

Send binary data along with a POST request

var response = try client.post("http://httpbin.org/post", .{ .content = "Gotta go fast!" });
defer response.deinit();

var tree = try response.json();
defer tree.deinit();

Stream a response

var response = try client.stream(.Get, "http://httpbin.org/", .{});
defer response.deinit();

while(true) {
    var buffer: [4096]u8 = undefined;
    var bytesRead = try response.read(&buffer);
    if (bytesRead == 0) {
        break;
    }
    std.debug.print("{}", .{buffer[0..bytesRead]});
}

Other standard HTTP method shortcuts:

  • client.connect
  • client.delete
  • client.head
  • client.options
  • client.patch
  • client.put
  • client.trace

Dependencies

License

requestz is released under the BSD Zero clause license. 🎉ðŸŧ