mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-05-03 07:22:27 +00:00
[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:
committed by
GitHub
parent
04b01da9fe
commit
e80fcf766e
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user