Skip to content

Commit 75ff881

Browse files
committed
Added APIGateway V2
1 parent 59e9d8b commit 75ff881

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

Sources/AWSLambdaEvents/APIGateway.swift

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,109 @@ extension APIGateway {
9090
}
9191
}
9292
}
93+
94+
// MARK: - V2 -
95+
96+
extension APIGateway {
97+
public struct V2 {}
98+
}
99+
100+
extension APIGateway.V2 {
101+
/// APIGateway.V2.Request contains data coming from the new HTTP API Gateway
102+
public struct Request: Codable {
103+
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
104+
public struct Context: Codable {
105+
public struct HTTP: Codable {
106+
public let method: String
107+
public let path: String
108+
public let `protocol`: String
109+
public let sourceIp: String
110+
public let userAgent: String
111+
}
112+
113+
/// Authorizer contains authorizer information for the request context.
114+
public struct Authorizer: Codable {
115+
/// JWT contains JWT authorizer information for the request context.
116+
public struct JWT {
117+
public let claims: [String: String]
118+
public let scopes: [String]
119+
}
120+
}
121+
122+
public let accountId: String
123+
public let apiId: String
124+
public let domainName: String
125+
public let domainPrefix: String
126+
public let stage: String
127+
public let requestId: String
128+
129+
public let http: HTTP
130+
public let authorizer: Authorizer?
131+
132+
/// The request time in format: 23/Apr/2020:11:08:18 +0000
133+
public let time: String
134+
public let timeEpoch: UInt64
135+
}
136+
137+
public let version: String
138+
public let routeKey: String
139+
public let rawPath: String
140+
public let rawQueryString: String
141+
142+
public let cookies: [String]?
143+
public let headers: HTTPHeaders
144+
public let queryStringParameters: [String: String]?
145+
public let pathParameters: [String: String]?
146+
147+
public let context: Context
148+
public let stageVariables: [String: String]?
149+
150+
public let body: String?
151+
public let isBase64Encoded: Bool
152+
153+
enum CodingKeys: String, CodingKey {
154+
case version
155+
case routeKey
156+
case rawPath
157+
case rawQueryString
158+
159+
case cookies
160+
case headers
161+
case queryStringParameters
162+
case pathParameters
163+
164+
case context = "requestContext"
165+
case stageVariables
166+
167+
case body
168+
case isBase64Encoded
169+
}
170+
}
171+
}
172+
173+
extension APIGateway.V2 {
174+
public struct Response: Codable {
175+
public let statusCode: HTTPResponseStatus
176+
public let headers: HTTPHeaders?
177+
public let multiValueHeaders: HTTPMultiValueHeaders?
178+
public let body: String?
179+
public let isBase64Encoded: Bool?
180+
public let cookies: [String]?
181+
182+
public init(
183+
statusCode: HTTPResponseStatus,
184+
headers: HTTPHeaders? = nil,
185+
multiValueHeaders: HTTPMultiValueHeaders? = nil,
186+
body: String? = nil,
187+
isBase64Encoded: Bool? = nil,
188+
cookies: [String]? = nil
189+
) {
190+
self.statusCode = statusCode
191+
self.headers = headers
192+
self.multiValueHeaders = multiValueHeaders
193+
self.body = body
194+
self.isBase64Encoded = isBase64Encoded
195+
self.cookies = cookies
196+
}
197+
}
198+
}

0 commit comments

Comments
 (0)