StartRouteAnalysis unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRestW rest;
bool success;
CkAuthAwsW authAws;
authAws.put_AccessKey(L"AWS_ACCESS_KEY");
authAws.put_SecretKey(L"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.)
authAws.put_Region(L"us-west-2");
authAws.put_ServiceName(L"networkmanager");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://networkmanager.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect(L"networkmanager.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
CkJsonObjectW json;
json.UpdateString(L"Destination.IpAddress",L"string");
json.UpdateString(L"Destination.TransitGatewayAttachmentArn",L"string");
json.UpdateInt(L"IncludeReturnPath",123);
json.UpdateString(L"Source.IpAddress",L"string");
json.UpdateString(L"Source.TransitGatewayAttachmentArn",L"string");
json.UpdateInt(L"UseMiddleboxes",123);
// The JSON request body created by the above code:
// {
// "Destination": {
// "IpAddress": "string",
// "TransitGatewayAttachmentArn": "string"
// },
// "IncludeReturnPath": boolean,
// "Source": {
// "IpAddress": "string",
// "TransitGatewayAttachmentArn": "string"
// },
// "UseMiddleboxes": boolean
// }
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"StartRouteAnalysis");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/global-networks/{globalNetworkId}/route-analyses",sbRequestBody,sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *DestinationCidrBlock = 0;
const wchar_t *Definition = 0;
int IsMiddlebox;
const wchar_t *NameTag = 0;
const wchar_t *RegisteredGatewayArn = 0;
const wchar_t *ResourceArn = 0;
const wchar_t *ResourceType = 0;
int Sequence;
const wchar_t *ResourceDefinition = 0;
int ResourceIsMiddlebox;
const wchar_t *ResourceNameTag = 0;
const wchar_t *ResourceRegisteredGatewayArn = 0;
const wchar_t *ResourceResourceArn = 0;
const wchar_t *ResourceResourceType = 0;
const wchar_t *IpAddress = jResp.stringOf(L"RouteAnalysis.Destination.IpAddress");
const wchar_t *TransitGatewayArn = jResp.stringOf(L"RouteAnalysis.Destination.TransitGatewayArn");
const wchar_t *TransitGatewayAttachmentArn = jResp.stringOf(L"RouteAnalysis.Destination.TransitGatewayAttachmentArn");
const wchar_t *ReasonCode = jResp.stringOf(L"RouteAnalysis.ForwardPath.CompletionStatus.ReasonCode");
const wchar_t *v_String = jResp.stringOf(L"RouteAnalysis.ForwardPath.CompletionStatus.ReasonContext.string");
const wchar_t *ResultCode = jResp.stringOf(L"RouteAnalysis.ForwardPath.CompletionStatus.ResultCode");
const wchar_t *GlobalNetworkId = jResp.stringOf(L"RouteAnalysis.GlobalNetworkId");
int IncludeReturnPath = jResp.IntOf(L"RouteAnalysis.IncludeReturnPath");
const wchar_t *OwnerAccountId = jResp.stringOf(L"RouteAnalysis.OwnerAccountId");
const wchar_t *CompletionStatusReasonCode = jResp.stringOf(L"RouteAnalysis.ReturnPath.CompletionStatus.ReasonCode");
const wchar_t *ReasonContextString = jResp.stringOf(L"RouteAnalysis.ReturnPath.CompletionStatus.ReasonContext.string");
const wchar_t *CompletionStatusResultCode = jResp.stringOf(L"RouteAnalysis.ReturnPath.CompletionStatus.ResultCode");
const wchar_t *RouteAnalysisId = jResp.stringOf(L"RouteAnalysis.RouteAnalysisId");
const wchar_t *SourceIpAddress = jResp.stringOf(L"RouteAnalysis.Source.IpAddress");
const wchar_t *SourceTransitGatewayArn = jResp.stringOf(L"RouteAnalysis.Source.TransitGatewayArn");
const wchar_t *SourceTransitGatewayAttachmentArn = jResp.stringOf(L"RouteAnalysis.Source.TransitGatewayAttachmentArn");
int StartTimestamp = jResp.IntOf(L"RouteAnalysis.StartTimestamp");
const wchar_t *Status = jResp.stringOf(L"RouteAnalysis.Status");
int UseMiddleboxes = jResp.IntOf(L"RouteAnalysis.UseMiddleboxes");
int i = 0;
int count_i = jResp.SizeOfArray(L"RouteAnalysis.ForwardPath.Path");
while (i < count_i) {
jResp.put_I(i);
DestinationCidrBlock = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].DestinationCidrBlock");
Definition = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.Definition");
IsMiddlebox = jResp.IntOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.IsMiddlebox");
NameTag = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.NameTag");
RegisteredGatewayArn = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.RegisteredGatewayArn");
ResourceArn = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.ResourceArn");
ResourceType = jResp.stringOf(L"RouteAnalysis.ForwardPath.Path[i].Resource.ResourceType");
Sequence = jResp.IntOf(L"RouteAnalysis.ForwardPath.Path[i].Sequence");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"RouteAnalysis.ReturnPath.Path");
while (i < count_i) {
jResp.put_I(i);
DestinationCidrBlock = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].DestinationCidrBlock");
ResourceDefinition = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.Definition");
ResourceIsMiddlebox = jResp.IntOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.IsMiddlebox");
ResourceNameTag = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.NameTag");
ResourceRegisteredGatewayArn = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.RegisteredGatewayArn");
ResourceResourceArn = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.ResourceArn");
ResourceResourceType = jResp.stringOf(L"RouteAnalysis.ReturnPath.Path[i].Resource.ResourceType");
Sequence = jResp.IntOf(L"RouteAnalysis.ReturnPath.Path[i].Sequence");
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "RouteAnalysis": {
// "Destination": {
// "IpAddress": "string",
// "TransitGatewayArn": "string",
// "TransitGatewayAttachmentArn": "string"
// },
// "ForwardPath": {
// "CompletionStatus": {
// "ReasonCode": "string",
// "ReasonContext": {
// "string": "string"
// },
// "ResultCode": "string"
// },
// "Path": [
// {
// "DestinationCidrBlock": "string",
// "Resource": {
// "Definition": "string",
// "IsMiddlebox": boolean,
// "NameTag": "string",
// "RegisteredGatewayArn": "string",
// "ResourceArn": "string",
// "ResourceType": "string"
// },
// "Sequence": number
// }
// ]
// },
// "GlobalNetworkId": "string",
// "IncludeReturnPath": boolean,
// "OwnerAccountId": "string",
// "ReturnPath": {
// "CompletionStatus": {
// "ReasonCode": "string",
// "ReasonContext": {
// "string": "string"
// },
// "ResultCode": "string"
// },
// "Path": [
// {
// "DestinationCidrBlock": "string",
// "Resource": {
// "Definition": "string",
// "IsMiddlebox": boolean,
// "NameTag": "string",
// "RegisteredGatewayArn": "string",
// "ResourceArn": "string",
// "ResourceType": "string"
// },
// "Sequence": number
// }
// ]
// },
// "RouteAnalysisId": "string",
// "Source": {
// "IpAddress": "string",
// "TransitGatewayArn": "string",
// "TransitGatewayAttachmentArn": "string"
// },
// "StartTimestamp": number,
// "Status": "string",
// "UseMiddleboxes": boolean
// }
// }
}