Skip to content

Commit 6d75d54

Browse files
committed
update documentation and dependencies
1 parent 5cb1ed1 commit 6d75d54

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ This library provides custom Lambda function wrappers which expose standard, abs
5151

5252
### Rationale and motivation
5353

54-
AWS Lambda supports a wide variety of event triggers, each with unique payloads and expected response objects. The Lambda method signature, however, only provides a raw event object and has no included mechanisms for simplifying payload parsing or response object creation. For example, API Gateway events include only the raw request body, leaving it up to developers to implement parsing themselves. Similarly, the developer is responsible for creating a response object which includes the correct HTTP status code and headers. This library exposes helpful abstractions like parsed HTTP bodies based on content-type headers, and success functions which create response objects with the correct status codes and headers for returning to API Gateway.
54+
AWS Lambda supports a wide variety of event triggers, each with unique payloads and expected response objects. The Lambda method signature, however, only provides a raw event object and has no included mechanisms for simplifying payload parsing or response object creation. For example API Gateway events include only the raw request body, leaving it up to developers to implement parsing themselves. Similarly the developer is responsible for creating a response object which includes the correct HTTP status code and headers. This library exposes helpful abstractions like parsed HTTP bodies based on content-type headers, and success functions which create response objects with the correct status codes and headers for returning to API Gateway.
5555

5656
_Feedback is much appreciated! If you have an idea for how this library can be improved (or just a complaint/criticism) then [please open an issue](https://github.com/manwaring/lambda-wrapper/issues/new)._
5757

@@ -67,11 +67,11 @@ Install and save the package:
6767

6868
If you want the wrapper to log request and response messages (helpful for debugging) set an environemnt variable for `LAMBDA_WRAPPER_LOG=true`.
6969

70-
If you want each invocation to be tagged with the AWS region, stage/environment, and Git revision simply set environment variables for each and the library will pick them up: `REGION=us-east-1`, `STAGE=prod`, `REVISION=f4ba682`. See [git-rev-sync](https://www.npmjs.com/package/git-rev-sync) and [serverless-plugin-git-variables](https://www.npmjs.com/package/serverless-plugin-git-variables) for libraries that can help you set git revision automatically.
70+
If you want each invocation to be tagged with the AWS region, stage/environment, and Git revision simply set environment variables for each and the library will pick them up, for example `REGION=us-east-1`, `STAGE=prod`, `REVISION=f4ba682`. See [git-rev-sync](https://www.npmjs.com/package/git-rev-sync) and [serverless-plugin-git-variables](https://www.npmjs.com/package/serverless-plugin-git-variables) for libraries that can help you set git revision automatically.
7171

7272
# Supported events
7373

74-
All of the events bellow have a corresponding wrapper which provides a deconstructable method signature exposing parsed/unmarshalled request parameters and helper response methods.
74+
Each event listed here has a wrapper which provides a deconstructable method signature exposing parsed/unmarshalled request parameters and helper response methods.
7575

7676
1. [API Gateway](#api-gateway)
7777
1. [API Gateway HTTP API](#api-gateway-http-api)
@@ -88,6 +88,7 @@ All of the events bellow have a corresponding wrapper which provides a deconstru
8888
```ts
8989
import { api } from '@manwaring/lambda-wrapper';
9090
import { CustomInterface } from './custom-interface';
91+
import { doSomething } from './you-code';
9192

9293
export const handler = api<CustomInterface>(async ({ body, path, success, invalid, error }) => {
9394
try {
@@ -103,7 +104,29 @@ export const handler = api<CustomInterface>(async ({ body, path, success, invali
103104
});
104105
```
105106

106-
By passing in CustomInterface as a generic type the method signature will cast the `body` object as an instance of CustomInterface, making TypeScript development easier (note that the generic is not required and the body parameter defaults to type `any`)
107+
By passing in CustomInterface as a generic type the method signature will cast the `body` object as an instance of CustomInterface, making TypeScript development easier. Note that the type is not required and the body property defaults to type `any`.
108+
109+
<details>
110+
<summary>Sample implementation without generic</summary>
111+
112+
```ts
113+
import { api } from '@manwaring/lambda-wrapper';
114+
import { doSomething } from './you-code';
115+
116+
export const handler = api(async ({ body, path, success, invalid, error }) => {
117+
try {
118+
const { pathParam1, pathParam2 } = path;
119+
if (!pathParam1) {
120+
return invalid();
121+
}
122+
const results = await doSomething(body, pathParam1, pathParam2);
123+
return success({ body: results });
124+
} catch (err) {
125+
return error({ err });
126+
}
127+
});
128+
```
129+
</details>
107130

108131
## Properties and methods available on wrapper signature
109132

@@ -581,6 +604,7 @@ Other than the raw payload from AWS the HTTP API method signature and response f
581604
```ts
582605
import { httpApi } from '@manwaring/lambda-wrapper';
583606
import { CustomInterface } from './custom-interface';
607+
import { doSomething } from './you-code';
584608

585609
export const handler = httpApi<CustomInterface>(async ({ body, path, success, invalid, error }) => {
586610
try {
@@ -596,7 +620,29 @@ export const handler = httpApi<CustomInterface>(async ({ body, path, success, in
596620
});
597621
```
598622

599-
By passing in CustomInterface as a generic type the method signature will cast the `body` object as an instance of CustomInterface, making TypeScript development easier (note that the generic is not required and the body parameter defaults to type `any`)
623+
By passing in CustomInterface as a generic type the method signature will cast the `body` object as an instance of CustomInterface, making TypeScript development easier. Note that the type is not required and the body property defaults to type `any`.
624+
625+
<details>
626+
<summary>Sample implementation without generic</summary>
627+
628+
```ts
629+
import { httpApi } from '@manwaring/lambda-wrapper';
630+
import { doSomething } from './you-code';
631+
632+
export const handler = httpApi(async ({ body, path, success, invalid, error }) => {
633+
try {
634+
const { pathParam1, pathParam2 } = path;
635+
if (!pathParam1) {
636+
return invalid();
637+
}
638+
const results = await doSomething(body, pathParam1, pathParam2);
639+
return success({ body: results });
640+
} catch (err) {
641+
return error({ err });
642+
}
643+
});
644+
```
645+
</details>
600646

601647
## Properties and methods available on wrapper signature
602648

0 commit comments

Comments
 (0)