Chilkat Online Tools

GetDataSource Swift3 Example

AWS AppSync

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

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    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: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "GetDataSource")

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/v1/apis/{apiId}/datasources/{name}", sb: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    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

    var DataSourceArn: String? = jResp.string(of: "dataSource.dataSourceArn")
    var Description: String? = jResp.string(of: "dataSource.description")
    var AwsRegion: String? = jResp.string(of: "dataSource.dynamodbConfig.awsRegion")
    var BaseTableTTL: Int = jResp.int(of: "dataSource.dynamodbConfig.deltaSyncConfig.baseTableTTL").intValue
    var DeltaSyncTableName: String? = jResp.string(of: "dataSource.dynamodbConfig.deltaSyncConfig.deltaSyncTableName")
    var DeltaSyncTableTTL: Int = jResp.int(of: "dataSource.dynamodbConfig.deltaSyncConfig.deltaSyncTableTTL").intValue
    var TableName: String? = jResp.string(of: "dataSource.dynamodbConfig.tableName")
    var UseCallerCredentials: Int = jResp.int(of: "dataSource.dynamodbConfig.useCallerCredentials").intValue
    var Versioned: Int = jResp.int(of: "dataSource.dynamodbConfig.versioned").intValue
    var ElasticsearchConfigAwsRegion: String? = jResp.string(of: "dataSource.elasticsearchConfig.awsRegion")
    var Endpoint: String? = jResp.string(of: "dataSource.elasticsearchConfig.endpoint")
    var AuthorizationType: String? = jResp.string(of: "dataSource.httpConfig.authorizationConfig.authorizationType")
    var SigningRegion: String? = jResp.string(of: "dataSource.httpConfig.authorizationConfig.awsIamConfig.signingRegion")
    var SigningServiceName: String? = jResp.string(of: "dataSource.httpConfig.authorizationConfig.awsIamConfig.signingServiceName")
    var HttpConfigEndpoint: String? = jResp.string(of: "dataSource.httpConfig.endpoint")
    var LambdaFunctionArn: String? = jResp.string(of: "dataSource.lambdaConfig.lambdaFunctionArn")
    var Name: String? = jResp.string(of: "dataSource.name")
    var OpenSearchServiceConfigAwsRegion: String? = jResp.string(of: "dataSource.openSearchServiceConfig.awsRegion")
    var OpenSearchServiceConfigEndpoint: String? = jResp.string(of: "dataSource.openSearchServiceConfig.endpoint")
    var RdsHttpEndpointConfigAwsRegion: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.awsRegion")
    var AwsSecretStoreArn: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.awsSecretStoreArn")
    var DatabaseName: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.databaseName")
    var DbClusterIdentifier: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.dbClusterIdentifier")
    var Schema: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.schema")
    var RelationalDatabaseSourceType: String? = jResp.string(of: "dataSource.relationalDatabaseConfig.relationalDatabaseSourceType")
    var ServiceRoleArn: String? = jResp.string(of: "dataSource.serviceRoleArn")
    var v_Type: String? = jResp.string(of: "dataSource.type")

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

    // {
    //   "dataSource": {
    //     "dataSourceArn": "string",
    //     "description": "string",
    //     "dynamodbConfig": {
    //       "awsRegion": "string",
    //       "deltaSyncConfig": {
    //         "baseTableTTL": number,
    //         "deltaSyncTableName": "string",
    //         "deltaSyncTableTTL": number
    //       },
    //       "tableName": "string",
    //       "useCallerCredentials": boolean,
    //       "versioned": boolean
    //     },
    //     "elasticsearchConfig": {
    //       "awsRegion": "string",
    //       "endpoint": "string"
    //     },
    //     "httpConfig": {
    //       "authorizationConfig": {
    //         "authorizationType": "string",
    //         "awsIamConfig": {
    //           "signingRegion": "string",
    //           "signingServiceName": "string"
    //         }
    //       },
    //       "endpoint": "string"
    //     },
    //     "lambdaConfig": {
    //       "lambdaFunctionArn": "string"
    //     },
    //     "name": "string",
    //     "openSearchServiceConfig": {
    //       "awsRegion": "string",
    //       "endpoint": "string"
    //     },
    //     "relationalDatabaseConfig": {
    //       "rdsHttpEndpointConfig": {
    //         "awsRegion": "string",
    //         "awsSecretStoreArn": "string",
    //         "databaseName": "string",
    //         "dbClusterIdentifier": "string",
    //         "schema": "string"
    //       },
    //       "relationalDatabaseSourceType": "string"
    //     },
    //     "serviceRoleArn": "string",
    //     "type": "string"
    //   }
    // }

}