In my iOS project, I need to implement the AWS SDK, as I successfully did in the Android version of that project.
I imported AWSMobileClient
and AWSAPIGateway
in my iOS project using Cocoapods.
Here is what I did in my Android project, that I want to replicate on iOS:
- I created an
AWSInterface
interface, where all my api endpoints are:
@Service(endpoint = "https://abcde12345.execute-api.eu-central-1.amazonaws.com/dev")
interface AWSInterface
{
@Operation(path = "/api-demo", method = "POST")
fun apiDemo(
@Parameter(name = "Content-Type", location = "header") contentType: String,
body: ApiDemoModel): RetourStatutWS
}
- and here is the
ApiDemoModel
, very simple:
class ApiDemoModel(val code: String)
- I created an
AWSInterfaceHolder
class, so I'll be able to call apis:
class AWSInterfaceHolder
{
var awsInterface: AWSInterface = ApiClientFactory()
.credentialsProvider(AWSMobileClient.getInstance())
.clientConfiguration(ClientConfiguration().withConnectionTimeout(30000))
.build(AWSInterface::class.java)
}
- I call my api, after a successful initialization of
AWSMobileClient
:
// AWSMobileClient is successfully initialized, I can call my api:
val awsInterfaceHolder = AWSInterfaceHolder()
awsInterfaceHolder.awsInterface.apiDemo(
"application/json",
ApiDemoModel("123456"))
How can I do the same for my iOS Swift project?
Thanks.
question from:https://stackoverflow.com/questions/66049702/how-to-call-an-aws-webservice-api-gateway-on-ios