Sample code for 30+ languages & platforms
Zig

REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)

See more REST Examples

Demonstrates how the autoReconnect argument to the Connect method is used.

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 requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

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

    // This example demonstrates the usage of the autoReconnect argument to the Connect method.
    // When autoReconnect is on, subsequent REST method calls will automatically re-connect
    // if necessary, using the same information (domain/IP address, port number, and TLS).
    const b_tls = false;
    const port = 80;
    const b_auto_reconnect = true;
    try rest.connect("dev.markitondemand.com", port, b_tls, b_auto_reconnect);

    // Get a stock quote:
    try rest.addQueryParam("symbol", "AAPL");
    var response_xml: [:0]const u8 = rest.fullRequestNoBody(alloc, "GET", "/MODApis/Api/v2/Quote") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    try xml.loadXml(response_xml);
    std.debug.print("AAPL LastPrice: {s}\n", .{try xml.getChildContent(alloc, "LastPrice")});

    // Get another stock quote.  If a new HTTP connection is required,
    // the REST object will automatically connect using the same parameters.
    try rest.addQueryParam("symbol", "AMZN");
    response_xml = rest.fullRequestNoBody(alloc, "GET", "/MODApis/Api/v2/Quote") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    try xml.loadXml(response_xml);
    std.debug.print("AMZN LastPrice: {s}\n", .{try xml.getChildContent(alloc, "LastPrice")});
}