@scloud/lambda-api 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +31 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Lambda API Gateway Proxy handler
2
+
3
+ A Lambda handler that routes API Gateway Proxy messages and returns an API Gateway Proxy Response.
4
+
5
+ This is a piece of useful boilerplate to handle the mechanics of routing, headers and cookies, catching any errors and handling 400, 405 and 500 errors (you can optionally handle 404 and 500 with your own handler functions).
6
+
7
+ ## Usage
8
+
9
+ Create your routes:
10
+
11
+ ```
12
+ import { types } from '@scloud/lambda-api';
13
+
14
+ const routes: types.Routes = {
15
+ '/ping': { GET: async (request: types.Request) => ({ statusCode: 200, body: {message: 'ok'} }) },
16
+ }
17
+ ```
18
+
19
+ Use `@scloud/lambda-api` in your Lambda handler:
20
+
21
+ ```
22
+ import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
23
+ import { apiHandler, helpers } from '@scloud/lambda-api';
24
+
25
+ export async function handler(event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> {
26
+ const result = await apiHandler(event, context, routes);
27
+ return result;
28
+ }
29
+ ```
30
+
31
+ The `apiHandler` function will call your route functions according to the method and path of the request, catching any errors and returning 404/405 if a path/method isn't defined, or 500 if an error is thrown.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scloud/lambda-api",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Lambda handler for API Gateway proxy requests",
5
5
  "main": "dist/index.js",
6
6
  "files": [