Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

ducdetronquito/requestz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. 🎉🍻