Sample code for 30+ languages & platforms
Zig

Send HTTPS Get Without Waiting for the Response

See more REST Examples

This example demonstrates sending an HTTP GET request without waiting for the response.

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();

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

    // Connect to the server using TLS
    const b_auto_reconnect = false;
    rest.connect("example.com", 443, true, b_auto_reconnect) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // Send a GET request to https://example.com/some/path
    rest.sendReqNoBody("GET", "/some/path") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // OK, the request was sent.
    // Close the connection.
    const max_wait_ms = 50;
    rest.disconnect(max_wait_ms) catch {};

    std.debug.print("GET Request Sent.\n", .{});
}