Chilkat Online Tools

GetGraphqlApi Objective-C Example

AWS AppSync

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

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

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
authAws.SecretKey = @"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.Region = @"us-west-2";
authAws.ServiceName = @"appsync";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://appsync.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"appsync.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"GetGraphqlApi"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/v1/apis/{apiId}" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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

NSString *authenticationType = 0;
int lambdaAuthorizerConfigAuthorizerResultTtlInSeconds;
NSString *lambdaAuthorizerConfigAuthorizerUri = 0;
NSString *lambdaAuthorizerConfigIdentityValidationExpression = 0;
int openIDConnectConfigAuthTTL;
NSString *openIDConnectConfigClientId = 0;
int openIDConnectConfigIatTTL;
NSString *openIDConnectConfigIssuer = 0;
NSString *userPoolConfigAppIdClientRegex = 0;
NSString *userPoolConfigAwsRegion = 0;
NSString *userPoolConfigUserPoolId = 0;

NSString *ApiId = [jResp StringOf: @"graphqlApi.apiId"];
NSString *Arn = [jResp StringOf: @"graphqlApi.arn"];
NSString *AuthenticationType = [jResp StringOf: @"graphqlApi.authenticationType"];
int AuthorizerResultTtlInSeconds = [[jResp IntOf: @"graphqlApi.lambdaAuthorizerConfig.authorizerResultTtlInSeconds"] intValue];
NSString *AuthorizerUri = [jResp StringOf: @"graphqlApi.lambdaAuthorizerConfig.authorizerUri"];
NSString *IdentityValidationExpression = [jResp StringOf: @"graphqlApi.lambdaAuthorizerConfig.identityValidationExpression"];
NSString *CloudWatchLogsRoleArn = [jResp StringOf: @"graphqlApi.logConfig.cloudWatchLogsRoleArn"];
int ExcludeVerboseContent = [[jResp IntOf: @"graphqlApi.logConfig.excludeVerboseContent"] intValue];
NSString *FieldLogLevel = [jResp StringOf: @"graphqlApi.logConfig.fieldLogLevel"];
NSString *Name = [jResp StringOf: @"graphqlApi.name"];
int AuthTTL = [[jResp IntOf: @"graphqlApi.openIDConnectConfig.authTTL"] intValue];
NSString *ClientId = [jResp StringOf: @"graphqlApi.openIDConnectConfig.clientId"];
int IatTTL = [[jResp IntOf: @"graphqlApi.openIDConnectConfig.iatTTL"] intValue];
NSString *Issuer = [jResp StringOf: @"graphqlApi.openIDConnectConfig.issuer"];
NSString *v_String = [jResp StringOf: @"graphqlApi.tags.string"];
NSString *UrisString = [jResp StringOf: @"graphqlApi.uris.string"];
NSString *AppIdClientRegex = [jResp StringOf: @"graphqlApi.userPoolConfig.appIdClientRegex"];
NSString *AwsRegion = [jResp StringOf: @"graphqlApi.userPoolConfig.awsRegion"];
NSString *DefaultAction = [jResp StringOf: @"graphqlApi.userPoolConfig.defaultAction"];
NSString *UserPoolId = [jResp StringOf: @"graphqlApi.userPoolConfig.userPoolId"];
NSString *WafWebAclArn = [jResp StringOf: @"graphqlApi.wafWebAclArn"];
int XrayEnabled = [[jResp IntOf: @"graphqlApi.xrayEnabled"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"graphqlApi.additionalAuthenticationProviders"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    authenticationType = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].authenticationType"];
    lambdaAuthorizerConfigAuthorizerResultTtlInSeconds = [[jResp IntOf: @"graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"] intValue];
    lambdaAuthorizerConfigAuthorizerUri = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerUri"];
    lambdaAuthorizerConfigIdentityValidationExpression = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.identityValidationExpression"];
    openIDConnectConfigAuthTTL = [[jResp IntOf: @"graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.authTTL"] intValue];
    openIDConnectConfigClientId = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.clientId"];
    openIDConnectConfigIatTTL = [[jResp IntOf: @"graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.iatTTL"] intValue];
    openIDConnectConfigIssuer = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.issuer"];
    userPoolConfigAppIdClientRegex = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.appIdClientRegex"];
    userPoolConfigAwsRegion = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.awsRegion"];
    userPoolConfigUserPoolId = [jResp StringOf: @"graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.userPoolId"];
    i = i + 1;
}

// A sample JSON response body parsed by the above code:

// {
//   "graphqlApi": {
//     "additionalAuthenticationProviders": [
//       {
//         "authenticationType": "string",
//         "lambdaAuthorizerConfig": {
//           "authorizerResultTtlInSeconds": number,
//           "authorizerUri": "string",
//           "identityValidationExpression": "string"
//         },
//         "openIDConnectConfig": {
//           "authTTL": number,
//           "clientId": "string",
//           "iatTTL": number,
//           "issuer": "string"
//         },
//         "userPoolConfig": {
//           "appIdClientRegex": "string",
//           "awsRegion": "string",
//           "userPoolId": "string"
//         }
//       }
//     ],
//     "apiId": "string",
//     "arn": "string",
//     "authenticationType": "string",
//     "lambdaAuthorizerConfig": {
//       "authorizerResultTtlInSeconds": number,
//       "authorizerUri": "string",
//       "identityValidationExpression": "string"
//     },
//     "logConfig": {
//       "cloudWatchLogsRoleArn": "string",
//       "excludeVerboseContent": boolean,
//       "fieldLogLevel": "string"
//     },
//     "name": "string",
//     "openIDConnectConfig": {
//       "authTTL": number,
//       "clientId": "string",
//       "iatTTL": number,
//       "issuer": "string"
//     },
//     "tags": {
//       "string": "string"
//     },
//     "uris": {
//       "string": "string"
//     },
//     "userPoolConfig": {
//       "appIdClientRegex": "string",
//       "awsRegion": "string",
//       "defaultAction": "string",
//       "userPoolId": "string"
//     },
//     "wafWebAclArn": "string",
//     "xrayEnabled": boolean
//   }
// }