Skip to content

Commit 86ee78d

Browse files
committed
add support for httpapi events
1 parent 54150a9 commit 86ee78d

File tree

13 files changed

+1981
-2868
lines changed

13 files changed

+1981
-2868
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [3.7.0]  (2020-08-03)
8+
9+
### Added
10+
11+
- Support for HTTP API 2.0 payloads
12+
713
## [3.6.3]  (2020-06-21)
814

915
### Fixed
@@ -247,6 +253,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
247253
- Update older libraries
248254
- Now publish from Git tags instead of master pushes
249255

256+
[3.7.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.6.3...v3.7.0
250257
[3.6.3]: https://github.com/manwaring/lambda-wrapper/compare/v3.6.2...v3.6.3
251258
[3.6.2]: https://github.com/manwaring/lambda-wrapper/compare/v3.6.1...v3.6.2
252259
[3.6.1]: https://github.com/manwaring/lambda-wrapper/compare/v3.6.0...v3.6.1

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [Optional configuration](#optional-configuration)
3737
1. [Supported events](#supported-events)
3838
- [API Gateway](#api-gateway)
39+
- [API Gateway HTTP API](#api-gateway-http-api)
3940
- [CloudFormation Custom Resource](#cloudformation-custom-resource)
4041
- [DynamoDB Stream](#dynamodb-stream)
4142
- [Lambda Authorizer](#lambda-authorizer)
@@ -74,6 +75,7 @@ If you want each invocation to be tagged with the AWS region, environment/, and
7475
All of the events bellow have a corresponding wrapper which provides a deconstructed method signature exposing parsed/unmarshalled request parameters and helper response methods.
7576

7677
1. [API Gateway](#api-gateway) with support for cors headers and 200, 302, 400, and 500 responses
78+
1. [API Gateway HTTP API](#api-gateway-http-api) with support for cors headers and 200, 302, 400, and 500 responses
7779
1. [CloudFormation Custom Resource](#cloudformation-custom-resource) with support for CloudFormation successes and failures
7880
1. [DynamoDB Stream](#dynamodb-stream) with support for success and failure responses
7981
1. [Lambda Authorizer](#lambda-authorizer) with support for creating access policies for successfully authorized requests
@@ -151,7 +153,55 @@ interface ApiResponse {
151153
}
152154
```
153155

154-
\*Note that each callback helper functions (success, invalid, redirect, error) includes CORS-enabling header information
156+
\*Note that each callback helper function (success, invalid, redirect, error) includes CORS-enabling header information
157+
158+
## API Gateway HTTP API
159+
160+
### Sample implementation
161+
162+
```ts
163+
import { httpApi } from '@manwaring/lambda-wrapper';
164+
import { CustomInterface } from './custom-interface';
165+
166+
// By passing in CustomInterface as a generic the async method signature will correctly identify newVersions as an array of CustomInterface, making TypeScript development easier (note that the generic is not required in JavaScript projects)
167+
export const handler = httpApi<CustomInterface>(async ({ body, path, success, error }) => {
168+
try {
169+
const { pathParam1, pathParam2 } = path;
170+
const results = await doSomething(body, pathParam1, pathParam2);
171+
return success(results);
172+
} catch (err) {
173+
return error(err);
174+
}
175+
});
176+
```
177+
178+
### Properties and methods available on wrapper signature
179+
180+
```ts
181+
export interface HttpApiSignature<T = any> {
182+
event: HttpApiEvent; // original event from https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-develop-integrations-lambda.proxy-format
183+
body: T; // JSON parsed body payload if exists (otherwise undefined)
184+
path: { [name: string]: string }; // path param payload as key-value pairs if exists (otherwise undefined)
185+
query: { [name: string]: string }; // query param payload as key-value pairs if exists (otherwise undefined)
186+
headers: { [name: string]: string }; // header payload as key-value pairs if exists (otherwise undefined)
187+
testRequest: boolean; // indicates if this is a test request - looks for a header matching process.env.TEST_REQUEST_HEADER (dynamic from application) or 'Test-Request' (default)
188+
auth: any; // auth context from custom authorizer if exists (otherwise undefined)
189+
success(payload?: any, replacer?: (this: any, key: string, value: any) => any): ApiResponse; // returns 200 status code with optional payload as body
190+
invalid(errors?: string[]): ApiResponse; // returns 400 status code with optional errors as body
191+
notFound(message?: string): ApiResponse; // returns 404 status code with optional message as body
192+
notAuthorized(message?: string): ApiResponse; // returns 403 status code with optional message as body
193+
redirect(url: string): ApiResponse; // returns 302 status code (redirect) with new url
194+
error(error?: any): ApiResponse; // returns 500 status code with optional error as body
195+
}
196+
197+
interface ApiResponse {
198+
statusCode: number;
199+
headers: { [name: string]: string | boolean };
200+
body?: string;
201+
}
202+
```
203+
204+
\*Note that each callback helper function (success, invalid, redirect, error) includes CORS-enabling header information
155205

156206
## CloudFormation Custom Resource
157207

0 commit comments

Comments
 (0)