Zig
Zig
SNS List Topics
See more Amazon SNS Examples
List the existing SNS topics.See SNS List Topics for more information.
Chilkat Zig Downloads
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();
// Connect to the Amazon AWS REST server.
// such as https://sns.us-west-2.amazonaws.com/
const b_tls = true;
const port = 443;
const b_auto_reconnect = true;
try rest.connect("sns.us-west-2.amazonaws.com", port, b_tls, b_auto_reconnect);
// Provide AWS credentials for the REST call.
const auth_aws = try chilkat.AuthAws.init();
defer auth_aws.deinit();
auth_aws.setAccessKey("AWS_ACCESS_KEY");
auth_aws.setSecretKey("AWS_SECRET_KEY");
// the region should match our URL above..
auth_aws.setRegion("us-west-2");
auth_aws.setServiceName("sns");
rest.setAuthAws(auth_aws) catch {};
rest.addQueryParam("Action", "ListTopics") catch {};
const response_xml = rest.fullRequestNoBody(alloc, "GET", "/") catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
// A successful response will have a status code equal to 200.
if (rest.getResponseStatusCode() != 200) {
std.debug.print("response status code = {d}\n", .{rest.getResponseStatusCode()});
std.debug.print("response status text = {s}\n", .{try rest.getResponseStatusText(alloc)});
std.debug.print("response header: {s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("response body: {s}\n", .{response_xml});
return;
}
// Examine the successful XML response (shown below)
const xml = try chilkat.Xml.init();
defer xml.deinit();
xml.loadXml(response_xml) catch {};
std.debug.print("{s}\n", .{try xml.getXml(alloc)});
// To iterate over the TopicArn's
_ = try xml.chilkatPath(alloc, "ListTopicsResult|Topics|$");
var i: i32 = 0;
const num_topics = xml.getNumChildren();
while (i < num_topics) {
xml.getChild2(i) catch {};
std.debug.print("{s}\n", .{try xml.getChildContent(alloc, "TopicArn")});
xml.getParent2() catch {};
i = i + 1;
}
xml.getRoot2();
// A sample successful response:
// <?xml version="1.0" encoding="utf-8" ?>
// <ListTopicsResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
// <ListTopicsResult>
// <Topics>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkat</TopicArn>
// </member>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkat123</TopicArn>
// </member>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkatses</TopicArn>
// </member>
// </Topics>
// </ListTopicsResult>
// <ResponseMetadata>
// <RequestId>54514f94-b07d-5f0b-9c8a-1ff85ff4ac65</RequestId>
// </ResponseMetadata>
// </ListTopicsResponse>
}