Sample code for 30+ languages & platforms
Zig

Clear a REST Response Body Stream Destination

See more REST Examples

Demonstrates Rest.ClearResponseBodyStream, which removes a response-stream destination previously configured with SetResponseBodyStream.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. Clearing the destination restores normal behavior, in which the full-request convenience methods return the response body rather than streaming it.

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;
    };

    // The file paths are relative to the application's current working directory.  Absolute paths
    // may also be used.  Supply the paths appropriate to your own environment.

    const resp_stream = try chilkat.Stream.init();
    defer resp_stream.deinit();
    resp_stream.setSinkFile("qa_output/response_body.dat");
    const b_auto_set_charset = true;
    const expected_status = 200;
    rest.setResponseBodyStream(expected_status, b_auto_set_charset, resp_stream) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // Clear the response-stream destination previously configured, so subsequent full-request calls
    // return the response body normally instead of streaming it.
    rest.clearResponseBodyStream();

    std.debug.print("Response body streaming cleared.\n", .{});
}