CreateDataSource Swift3 Example
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
}
// 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
let json = CkoJsonObject()!
json.update("description", value: "string")
json.update("dynamodbConfig.awsRegion", value: "string")
json.updateInt("dynamodbConfig.deltaSyncConfig.baseTableTTL", value: 123)
json.update("dynamodbConfig.deltaSyncConfig.deltaSyncTableName", value: "string")
json.updateInt("dynamodbConfig.deltaSyncConfig.deltaSyncTableTTL", value: 123)
json.update("dynamodbConfig.tableName", value: "string")
json.updateInt("dynamodbConfig.useCallerCredentials", value: 123)
json.updateInt("dynamodbConfig.versioned", value: 123)
json.update("elasticsearchConfig.awsRegion", value: "string")
json.update("elasticsearchConfig.endpoint", value: "string")
json.update("httpConfig.authorizationConfig.authorizationType", value: "string")
json.update("httpConfig.authorizationConfig.awsIamConfig.signingRegion", value: "string")
json.update("httpConfig.authorizationConfig.awsIamConfig.signingServiceName", value: "string")
json.update("httpConfig.endpoint", value: "string")
json.update("lambdaConfig.lambdaFunctionArn", value: "string")
json.update("name", value: "string")
json.update("openSearchServiceConfig.awsRegion", value: "string")
json.update("openSearchServiceConfig.endpoint", value: "string")
json.update("relationalDatabaseConfig.rdsHttpEndpointConfig.awsRegion", value: "string")
json.update("relationalDatabaseConfig.rdsHttpEndpointConfig.awsSecretStoreArn", value: "string")
json.update("relationalDatabaseConfig.rdsHttpEndpointConfig.databaseName", value: "string")
json.update("relationalDatabaseConfig.rdsHttpEndpointConfig.dbClusterIdentifier", value: "string")
json.update("relationalDatabaseConfig.rdsHttpEndpointConfig.schema", value: "string")
json.update("relationalDatabaseConfig.relationalDatabaseSourceType", value: "string")
json.update("serviceRoleArn", value: "string")
json.update("type", value: "string")
// The JSON request body created by the above code:
// {
// "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"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "CreateDataSource")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/v1/apis/{apiId}/datasources", requestBody: sbRequestBody, responseBody: 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"
// }
// }
}