1.4.0 • Published 5 years ago

bragg v1.4.0

Weekly downloads
1,029
License
MIT
Repository
github
Last release
5 years ago

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.

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

app.use(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.

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

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

app.onError(err => {
	console.error(err.message);

	return cleanUp();	// Async cleanup process
});

exports.handler = app.listen();

Middlewares

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

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

app.use(() => {
	return 'Foo';
});

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

app.use((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

1.4.0

5 years ago

1.3.0

7 years ago

2.3.0

8 years ago

2.2.0

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago