|
1 | 1 | [](https://serverless-api.com/) |
2 | 2 |
|
3 | | -[](https://github.com/jeremydaly/lambda-api/actions/workflows/build.yml) |
| 3 | +[](https://github.com/jeremydaly/lambda-api/actions/workflows/build.yml) |
4 | 4 | [](https://www.npmjs.com/package/lambda-api) |
5 | 5 | [](https://www.npmjs.com/package/lambda-api) |
6 | 6 | [](https://coveralls.io/github/jeremydaly/lambda-api?branch=main) |
|
9 | 9 |
|
10 | 10 | Lambda API is a lightweight web framework for AWS Lambda using AWS API Gateway Lambda Proxy Integration or ALB Lambda Target Support. This closely mirrors (and is based on) other web frameworks like Express.js and Fastify, but is significantly stripped down to maximize performance with Lambda's stateless, single run executions. |
11 | 11 |
|
| 12 | +## Using AWS SDK v2? |
| 13 | + |
| 14 | +lambda-api@v1 is using AWS SDK v3. |
| 15 | +If you are using AWS SDK v2, please use lambda-api@v0.12.0. |
| 16 | + |
12 | 17 | ## Simple Example |
13 | 18 |
|
14 | 19 | ```javascript |
@@ -147,6 +152,7 @@ Require the `lambda-api` module into your Lambda handler script and instantiate |
147 | 152 | | serializer | `Function` | Optional object serializer function. This function receives the `body` of a response and must return a string. Defaults to `JSON.stringify` | |
148 | 153 | | version | `String` | Version number accessible via the `REQUEST` object | |
149 | 154 | | errorHeaderWhitelist | `Array` | Array of headers to maintain on errors | |
| 155 | +| s3Config | `Object` | Optional object to provide as config to S3 sdk. [S3ClientConfig](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html) | |
150 | 156 |
|
151 | 157 | ```javascript |
152 | 158 | // Require the framework and instantiate it with optional version and base parameters |
@@ -481,21 +487,22 @@ res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') |
481 | 487 | The `header` method allows for you to set additional headers to return to the client. By default, just the `content-type` header is sent with `application/json` as the value. Headers can be added or overwritten by calling the `header()` method with two string arguments. The first is the name of the header and then second is the value. You can utilize multi-value headers by specifying an array with multiple values as the `value`, or you can use an optional third boolean parameter and append multiple headers. |
482 | 488 |
|
483 | 489 | ```javascript |
484 | | -api.get('/users', (req,res) => { |
485 | | - res.header('content-type','text/html').send('<div>This is HTML</div>') |
486 | | -}) |
| 490 | +api.get('/users', (req, res) => { |
| 491 | + res.header('content-type', 'text/html').send('<div>This is HTML</div>'); |
| 492 | +}); |
487 | 493 |
|
488 | 494 | // Set multiple header values |
489 | | -api.get('/users', (req,res) => { |
490 | | - res.header('someHeader',['foo','bar').send({}) |
491 | | -}) |
| 495 | +api.get('/users', (req, res) => { |
| 496 | + res.header('someHeader', ['foo', 'bar']).send({}); |
| 497 | +}); |
492 | 498 |
|
493 | 499 | // Set multiple header by adding to existing header |
494 | | -api.get('/users', (req,res) => { |
495 | | - res.header('someHeader','foo') |
496 | | - .header('someHeader','bar',true) // append another value |
497 | | - .send({}) |
498 | | -}) |
| 500 | +api.get('/users', (req, res) => { |
| 501 | + res |
| 502 | + .header('someHeader', 'foo') |
| 503 | + .header('someHeader', 'bar', true) // append another value |
| 504 | + .send({}); |
| 505 | +}); |
499 | 506 | ``` |
500 | 507 |
|
501 | 508 | **NOTE:** Header keys are converted and stored as lowercase in compliance with [rfc7540 8.1.2. HTTP Header Fields](https://tools.ietf.org/html/rfc7540) for HTTP/2. Header convenience methods (`getHeader`, `hasHeader`, and `removeHeader`) automatically ignore case. |
|
0 commit comments