Skip to content

Commit f32927f

Browse files
committed
externalize JSONENcoder()
1 parent 0d3903b commit f32927f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Examples/APIGateway/Sources/main.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import AWSLambdaEvents
1616
import AWSLambdaRuntime
1717
import class Foundation.JSONEncoder
1818

19+
let encoder = JSONEncoder()
1920
let runtime = LambdaRuntime {
2021
(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response in
2122

@@ -25,8 +26,8 @@ let runtime = LambdaRuntime {
2526
header["content-type"] = "application/json"
2627

2728
// echo the request in the response
28-
let data = try JSONEncoder().encode(event)
29-
let response = String(data: data, encoding: .utf8)
29+
let data = try encoder.encode(event)
30+
let response = String(decoding: data, as: Unicode.UTF8.self)
3031

3132
return APIGatewayV2Response(statusCode: .ok, headers: header, body: response)
3233
}

0 commit comments

Comments
 (0)