Sample code for 30+ languages & platforms
Zig

Send a Bodyless REST Request into a StringBuilder

See more REST Examples

Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.

Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const rest = try chilkat.Rest.init();
    defer rest.deinit();
    const b_tls = true;
    const b_auto_reconnect = true;
    rest.connect("example.com", 443, b_tls, b_auto_reconnect) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // FullRequestNoBodySb sends a request with no body and stores the text response body in a
    // StringBuilder.
    const sb_response = try chilkat.StringBuilder.init();
    defer sb_response.deinit();
    rest.fullRequestNoBodySb("GET", "/api/items/123", sb_response) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    const response_text = sb_response.getAsString(alloc) catch {
        std.debug.print("{s}\n", .{try sb_response.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{response_text});
}