Skip to content

Commit

Permalink
Compression docs in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Mar 16, 2021
1 parent f69907a commit f0dd13b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Whatever you decide is best for your use case, **Lambda API** is there to suppor
- [Error Logging](#error-logging)
- [Namespaces](#namespaces)
- [CORS Support](#cors-support)
- [Compression](#compression)
- [Execution Stacks](#execution-stacks)
- [Lambda Proxy Integration](#lambda-proxy-integration)
- [ALB Integration](#alb-integration)
Expand Down Expand Up @@ -1340,6 +1341,24 @@ You can also use the `cors()` ([see here](#corsoptions)) convenience method to a

Conditional route support could be added via middleware or with conditional logic within the `OPTIONS` route.

## Compression
Currently, API Gateway HTTP APIs do not support automatic compression out of the box, but that doesn't mean the Lambda can't return a compressed response. In order to create a compressed response instantiate the API with `isBase64` set to true, and a custom serializer that returns a compressed response as a base64 encoded string. Also, don't forget to set the correct `content-encoding` header:

```javascript
const zlib = require('zlib')

const api = require('lambda-api')({
isBase64: true,
headers: {
'content-encoding': ['gzip']
},
serializer: body => {
const json = JSON.stringify(body)
return zlib.gzipSync(json).toString('base64')
}
})
```

## Execution Stacks
Lambda API v0.10 introduced execution stacks as a way to more efficiently process middleware. Execution stacks are automatically created for you when adding routes and middleware using the standard route convenience methods, as well as `METHOD()` and `use()`. This is a technical implementation that has made method-based middleware and additional wildcard functionality possible.

Expand Down

0 comments on commit f0dd13b

Please sign in to comment.