Lambda API: v0.9 Released
v0.9 adds new features to give developers better control over error handling and serialization. Plus TypeScript support and additional API Gateway inputs.
Lambda API v0.9 adds new features to give developers better control over error handling and serialization. A TypeScript declaration file has also been added along with some additional API Gateway inputs that are now available in the REQUEST
object.
NPM: https://www.npmjs.com/package/lambda-api
GitHub: https://github.com/jeremydaly/lambda-api
New Error Types
Lambda API now provides several different types of errors that can be used by your application. RouteError
, MethodError
, ResponseError
, and FileError
will all be passed to your error middleware. ConfigurationError
s will throw an exception when you attempt to .run()
your route and can be caught in a try/catch
block. Most error types contain additional properties that further detail the issue.
javascriptconst errorHandler = (err,req,res,next) => { if (err.name === 'RouteError') { // do something with route error } else if (err.name === 'FileError') { // do something with file error } // continue next() })
Custom Serializers
By default, Lambda API will serialize objects with JSON.stringify()
. If you want more fine-grained control over serialization, you can now add a serializer
property to the configuration options when instantiating the API.
javascriptconst api = require('lambda-api')({ version: 'v1.0', serializer: myCustomSerializer });
Additional API Gateway Inputs
Lambda API now passes through additional API Gateway inputs directly into the REQUEST
object including pathParameters
, stageVariables
and isBase64Encoded
.
TypeScript Support
Thanks to an incredible amount of work by @hassankhan, a TypeScript declaration file has been added to support your projects. Just import 'lambda-api' into your TypeScript handler.
javascript// import Lambda API and TypeScript declarations import API from 'lambda-api' // instantiate the API const api = API({ version: 'v1', logger: { level: 'debug' } });
Full Release Notes: https://github.com/jeremydaly/lambda-api/releases/tag/v0.9.0
NPM: https://www.npmjs.com/package/lambda-api
GitHub: https://github.com/jeremydaly/lambda-api