[examples] Update APIGateway example with the new APIGatewayResponse initializer (#437)

After the merge of
https://github.com/swift-server/swift-aws-lambda-events/pull/86
I updated the `APIGatewayV2Response` example to use the new initializer
This commit is contained in:
Sébastien Stormacq
2024-12-24 08:40:46 +01:00
committed by GitHub
parent 04b01da9fe
commit e80fcf766e
+1 -11
View File
@@ -15,13 +15,6 @@
import AWSLambdaEvents
import AWSLambdaRuntime
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
let encoder = JSONEncoder()
let runtime = LambdaRuntime {
(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response in
@@ -31,10 +24,7 @@ let runtime = LambdaRuntime {
header["content-type"] = "application/json"
// echo the request in the response
let data = try encoder.encode(event)
let response = String(decoding: data, as: Unicode.UTF8.self)
return APIGatewayV2Response(statusCode: .ok, headers: header, body: response)
return try APIGatewayV2Response(statusCode: .ok, headers: header, encodableBody: event)
}
try await runtime.run()