JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1100
  • Score
    100M100P100Q108791F
  • License MIT

AWS Lambda web framework

Package Exports

  • bragg

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bragg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bragg Build Status

AWS λ web framework

This framework is heavily inspired by koa.

Install

$ npm install --save bragg

Usage

Simple example

Adding a single function as middleware is quite easy. The following example will succeed the lambda function with the value Foo Bar.

var bragg = require('bragg');
var app = bragg();

app.use(function (ctx) {
    ctx.body = 'Foo Bar';
});

exports.handler = app.listen();

Promise support

If a promise is assigned to the body property, it will be resolved before sending the result to the client.

var Promise = require('pinkie-promise');
var bragg = require('bragg');
var app = bragg();

app.use(function (ctx) {
    ctx.body = Promise.resolve('Foo Bar');
});

exports.handler = app.listen();

Middlewares

Multiple middlewares will be executed one after the other. The result of the following example is Foo Bar Baz.

var Promise = require('pinkie-promise');
var bragg = require('bragg');
var app = bragg();

app.use(function () {
    return 'Foo';
});

app.use(function (ctx, result) {
    return Promise.resolve(result + ' Bar');
});

app.use(function (ctx, result) {
    ctx.body = result + ' Baz';
});

exports.handler = app.listen();

Mapping template

In order for you to use parameters provided through API Gateway, you should add a mapping template in the integration request.

#set($path = $input.params().path)
#set($qs = $input.params().querystring)
#set($identity = $context.identity)
{
    "identity": {
        #foreach($key in $identity.keySet())
            "$key": "$util.escapeJavaScript($identity.get($key))"
        #if($foreach.hasNext), #end
        #end
    },
    "params": {
        #foreach($key in $path.keySet())
            "$key": "$path.get($key)"
        #if($foreach.hasNext), #end
        #end
    },
    "query": {
        #foreach($key in $qs.keySet())
            "$key": "$qs.get($key)"
        #if($foreach.hasNext), #end
        #end
    },
    "body": $input.json('$')
}

These properties will then be available in the request object in the middleware function.

License

MIT © Sam Verschueren