Sample code for 30+ languages & platforms
Zig

Amazon Voice ID - Describe Domain

See more Amazon Voice ID Examples

Describes the specified domain.

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

    const auth_aws = try chilkat.AuthAws.init();
    defer auth_aws.deinit();
    auth_aws.setAccessKey("AWS_ACCESS_KEY");
    auth_aws.setSecretKey("AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    auth_aws.setRegion("us-west-2");
    auth_aws.setServiceName("voiceid");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(auth_aws) catch {};

    // URL: https://voiceid.us-west-2.amazonaws.com/
    const b_tls = true;
    const port = 443;
    const b_auto_reconnect = true;
    // Use the same region as specified above.
    rest.connect("voiceid.us-west-2.amazonaws.com", port, b_tls, b_auto_reconnect) catch {
        std.debug.print("ConnectFailReason: {d}\n", .{rest.getConnectFailReason()});
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //     "DomainId": "<domainId>"
    // }
    //

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("DomainId", "<domainId>") catch {};

    rest.addHeader("Content-Type", "application/x-amz-json-1.0") catch {};
    rest.addHeader("X-Amz-Target", "VoiceID.DescribeDomain") catch {};
    rest.addHeader("Accept-Encoding", "identity") catch {};

    const sb_request_body = try chilkat.StringBuilder.init();
    defer sb_request_body.deinit();
    json.emitSb(sb_request_body) catch {};
    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    rest.fullRequestSb("POST", "/", sb_request_body, sb_response_body) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    const resp_status_code = rest.getResponseStatusCode();
    std.debug.print("response status code = {d}\n", .{resp_status_code});
    if (resp_status_code != 200) {
        std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try rest.getResponseHeader(alloc)});
        std.debug.print("Response Body:\n", .{});
        std.debug.print("{s}\n", .{try sb_response_body.getAsString(alloc)});
        return;
    }

    const json_response = try chilkat.JsonObject.init();
    defer json_response.deinit();
    json_response.loadSb(sb_response_body) catch {};

    json_response.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json_response.emit(alloc)});

    // If successful, the response status code is 200, and the response syntax:

    // {
    //    "Domain": {
    //       "Arn": "string",
    //       "CreatedAt": number,
    //       "Description": "string",
    //       "DomainId": "string",
    //       "DomainStatus": "string",
    //       "Name": "string",
    //       "ServerSideEncryptionConfiguration": {
    //          "KmsKeyId": "string"
    //       },
    //       "UpdatedAt": number
    //    }
    // }

    _ = try json_response.stringOf(alloc, "Domain.Arn");
    _ = json_response.intOf("Domain.CreatedAt");
    _ = try json_response.stringOf(alloc, "Domain.Description");
    _ = try json_response.stringOf(alloc, "Domain.DomainId");
    _ = try json_response.stringOf(alloc, "Domain.DomainStatus");
    _ = try json_response.stringOf(alloc, "Domain.Name");
    _ = try json_response.stringOf(alloc, "Domain.ServerSideEncryptionConfiguration.KmsKeyId");
    _ = json_response.intOf("Domain.UpdatedAt");
}