Skip to content

Commit e80fcf7

Browse files
authored
[examples] Update APIGateway example with the new APIGatewayResponse initializer (#437)
After the merge of swift-server/swift-aws-lambda-events#86 I updated the `APIGatewayV2Response` example to use the new initializer
1 parent 04b01da commit e80fcf7

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

Diff for: Examples/APIGateway/Sources/main.swift

+1-11
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
import AWSLambdaEvents
1616
import AWSLambdaRuntime
1717

18-
#if canImport(FoundationEssentials)
19-
import FoundationEssentials
20-
#else
21-
import Foundation
22-
#endif
23-
24-
let encoder = JSONEncoder()
2518
let runtime = LambdaRuntime {
2619
(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response in
2720

@@ -31,10 +24,7 @@ let runtime = LambdaRuntime {
3124
header["content-type"] = "application/json"
3225

3326
// echo the request in the response
34-
let data = try encoder.encode(event)
35-
let response = String(decoding: data, as: Unicode.UTF8.self)
36-
37-
return APIGatewayV2Response(statusCode: .ok, headers: header, body: response)
27+
return try APIGatewayV2Response(statusCode: .ok, headers: header, encodableBody: event)
3828
}
3929

4030
try await runtime.run()

0 commit comments

Comments
 (0)