Skip to content

Commit ce61751

Browse files
author
Sebastien Stormacq
committed
add multi decoding strategy to the LambdaStreaming+Codable example
1 parent 21b6ca7 commit ce61751

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Examples/Streaming+Codable/Sources/LambdaStreaming+Codable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,17 @@ public struct StreamingLambdaCodableAdapter<
9090

9191
var decodedBody: Handler.Event!
9292

93+
// Try to decode the event. It first tries FunctionURLRequest, then APIGatewayRequest, then "as-is"
94+
9395
// try to decode the event as a FunctionURLRequest, then fetch its body attribute
9496
if let request = try? self.decoder.decode(FunctionURLRequest.self, from: event) {
9597
// decode the body as user-provided JSON type
9698
// this function handles the base64 decoding when needed
9799
decodedBody = try request.decodeBody(Handler.Event.self)
100+
} else if let request = try? self.decoder.decode(APIGatewayRequest.self, from: event) {
101+
// decode the body as user-provided JSON type
102+
// this function handles the base64 decoding when needed
103+
decodedBody = try request.decodeBody(Handler.Event.self)
98104
} else {
99105
// try to decode the event "as-is" with the provided JSON type
100106
decodedBody = try self.decoder.decode(Handler.Event.self, from: event)

0 commit comments

Comments
 (0)