Lambda API: v0.7 Released
v0.7 adds features to control middleware execution based on path plus parsing of the AWS Lambda context object. ESLint and coverage reports were also added.
Lambda v0.7 is here! New features include allowing middleware to accept an optional path
argument that supports multiple paths, wildcards, and parameter matching to better control middleware execution. Plus additional parsing of the AWS Lambda context
object for use in your applications. In an effort to ensure code quality and adequate test coverage, ESLint was added as well as coverage reports using Istanbul and Coveralls.
NPM: https://www.npmjs.com/package/lambda-api
GitHub: https://github.com/jeremydaly/lambda-api
Restricting middleware execution to certain path(s)
By default, middleware will execute on every path. If you only need it to execute for specific paths, pass the path (or array of paths) as the first parameter to the use function.
javascript// Single path api.use('/users', (req,res,next) => { next() }) // Wildcard path api.use('/users/*', (req,res,next) => { next() }) // Multiple path api.use(['/users','/posts'], (req,res,next) => { next() }) // Parameterized paths api.use('/users/:userId',(req,res,next) => { next() }) // Multiple paths with parameters and wildcards api.use(['/comments','/users/:userId','/posts/*'],(req,res,next) => { next() })
Path matching checks both the supplied path
and the defined route
. This means that parameterized paths can be matched by either the parameter (e.g. /users/:param1
) or by an exact matching path (e.g. /users/123
).
AWS Lambda Context Parsing
Lambda API now automatically parses the context
object passed into the main handler function to give better access to this data within your middleware and routes. The REQUEST
object now contains an id
key that contains the awsRequestId
as well as a context
key that references the passed context directly. Access the clientContext
, log_stream_name
, identity
and more using REQUEST.context
. You can also call REQUEST.context.getRemainingTimeInMillis()
to obtain the remaining execution time.
Test Coverage and ESLint
As we get closer to releasing a solid "version 1.0" of Lambda API, we want to ensure that regressions don't creep into our code. We've added test coverage reporting with Istanbul and Coveralls as well as ESLint to ensure code quality.
Full Release Notes: https://github.com/jeremydaly/lambda-api/releases/tag/v0.7.0