Claudia 2.0

Claudia 2.0 is now available on NPM, along with Claudia API Builder and Claudia Bot Builder 2.0 versions, bringing support for dynamic response codes, easier custom header control, lambda proxy APIs, generic method handlers and wildcard path parameters, and integrating with the latest AWS API Gateway release.

Easier dynamic request processing

The most important new benefit for developers is probably being able to specify a response status code dynamically. Use the optional third argument to the ApiResponse constructor:

api.get('/programmatic-codes', function () {
	return new api.ApiResponse('OK', {'Content-Type': 'text/plain'}, 202);
});

The new API Gateway integration also makes it easier to support dynamic response headers, so you no longer need to enumerate all the headers upfront.

You can also use the new ANY mapping type to wire up a handler for all supported HTTP methods:

api.any('/generic', function (request) {
  return 'I got called with ' + request.context.method;
});

Check out these example projects demonstrating the new features:

Using the API Gateway Proxy Request object

When we released the first version of Claudia, there was no quick and easy way to build web APIs on Lambda with API Gateway. Claudia API Builder allowed developers to use simple request handlers, as expected from a modern light-weight web server. A big part of that was creating a generic request object interface, that packaged all the request parameters, headers and authentication info. With the September 2016 update, API Gateway caught on significantly, offering their own version of the generic request object, containing mostly the same information, but with slightly different key names and structure.

With version 2.x, Claudia API Builder allows you to choose the format of the request object for your handlers. By default, it will wrap the API Gateway Proxy object and convert it internally into the current interface, to keep backwards compatibility. Pass AWS_PROXY to the ApiBuilder constructor to turn off the conversion, and receive the API Gateway Proxy Request object directly:

var ApiBuilder = require('claudia-api-builder'),
    api = new ApiBuilder('AWS_PROXY');

api.get('/', function (request, context) {
  // request is now the API Gateway Proxy Object
});

Going forward, it probably makes more sense to just adopt the API Gateway Proxy object and use it directly, as that would allow you to benefit from the new features of API Gateway as soon as they are released.

Deploying proxy APIs

As an alternative to using claudia-api-builder, you can now also deploy API Gateway integrations that just proxy all request information to your Lambda function. Claudia 2.0 supports that with the additional --deploy-proxy-api argument. This is a good option for integrating existing web frameworks and doing more complex integrations, instead of just managing a simple Web API.

Why the major version change?

The September 2016 API Gateway update last week introduced several major changes that make it easier to link Lambda and API Gateway, replacing a lot of the functionality that Claudia did separately in version 1.x. There were several major underlying changes that require updating both the deployment tool and API builders at the same time, hence the bump to a major version. That will ensure that people don’t update only one component by mistake.

We’re also using this opportunity to do some house-keeping and drop support for Node 0.10 which is not going to be supported in Lambda any more soon. We’ll no longer test Claudia modules with 0.10, so if you still need to use 0.10 APIs, then use 1.x version of Claudia. Going forward, we’ll also use this opportunity to start switching the source code to ES6, and update the development toolkit a bit, moving away from jshint/jscs to eslint.

The new version is completely backwards compatible with client code for 1.x, but several features that are no longer necessary are deprecated. Check out Migrating to 2.0 tutorial for more information.

Interested in Claudia.js? Get notified when we release a new version.

Low-volume, high value mailing list, no ads or spam.