mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-05-03 07:22:27 +00:00
c915322eca
motivation: define stable API in preperation 1.0 release changes: * require swift 5.7, remove redundant backwards compatibility code * make LambdaHandler, EventLoopLambdaHandler, and ByteBufferLambdaHandler disjointed protocols to reduce API surface area * create coding wrappers for LambdaHandler and EventLoopLambdaHandler to provide bridge to ByteBufferLambdaHandler * reuse output ByteBuffer to reduce allocations * add new SimpleLambdaHandler with no-op initializer for simple lambda use cases * update callsites and tests * update examples Co-authored-by: Yim Lee <yim_lee@apple.com> Co-authored-by: Fabian Fett <fabianfett@apple.com>
35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftAWSLambdaRuntime open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import AWSLambdaRuntime
|
|
|
|
struct Request: Codable {
|
|
let body: String
|
|
}
|
|
|
|
struct Response: Codable {
|
|
let body: String
|
|
}
|
|
|
|
// in this example we are receiving and responding with codables. Request and Response above are examples of how to use
|
|
// codables to model your request and response objects
|
|
|
|
@main
|
|
struct MyLambda: SimpleLambdaHandler {
|
|
func handle(_ event: Request, context: LambdaContext) async throws -> Response {
|
|
// as an example, respond with the input event's reversed body
|
|
Response(body: String(event.body.reversed()))
|
|
}
|
|
}
|