11
2- [ ![ Build Status] ( https://travis-ci.org/WeltN24 /aws-lambda-router.svg?branch=master )] ( https://travis-ci.org/WeltN24 /aws-lambda-router )
2+ [ ![ Build Status] ( https://travis-ci.org/spring-media /aws-lambda-router.svg?branch=master )] ( https://travis-ci.org/spring-media /aws-lambda-router )
33[ ![ npm version] ( https://badge.fury.io/js/aws-lambda-router.svg )] ( https://badge.fury.io/js/aws-lambda-router )
44[ ![ dependencies] ( https://david-dm.org/WeltN24/aws-lambda-router.svg )] ( https://www.npmjs.com/package/aws-lambda-router )
55
@@ -49,27 +49,6 @@ exports.handler = router.handler(
4949 path: ' /:id' ,
5050 method: ' DELETE' ,
5151 action : request => deleteSomething (request .paths .id )
52- },
53- {
54- path: ' /custom-response-object' ,
55- action: ' GET' ,
56- action : request => {
57- return {
58- // Allow for custom status codes depending on execution.
59- statusCode: 400 ,
60- // Headers will merge with CORs headers when enabled.
61- // Will merge with Content-Type: application/json
62- headers: {
63- ' x-fake-header' : ' x-value'
64- },
65- // When returning a custom response object, a key of body is required
66- // The value of body needs to be JSON stringified, this matches
67- // the expected response for an AWS Lambda.
68- body: JSON .stringify ({
69- foo: ' bar'
70- })
71- }
72- }
7352 }
7453 ],
7554 debug: true ,
@@ -96,6 +75,30 @@ exports.handler = router.handler(
9675});
9776```
9877
78+ ### Custom response
79+
80+ Per default a status code 200 will be returned. This behavior can be override.
81+
82+ By providing body in the returned object you can modify statuscode and response headers.
83+
84+ ``` js
85+ return {
86+ // Allow for custom status codes depending on execution.
87+ statusCode: 218 ,
88+ // Headers will merge with CORs headers when enabled.
89+ // Will merge with Content-Type: application/json
90+ headers: {
91+ ' x-new-header' : ' another-value'
92+ },
93+ // When returning a custom response object, a key of body is required
94+ // The value of body needs to be JSON stringified, this matches
95+ // the expected response for an AWS Lambda.
96+ body: JSON .stringify ({
97+ foo: ' bar'
98+ })
99+ };
100+ ```
101+
99102## local developement
100103
101104The best is to work with ``` npm link ```
@@ -105,6 +108,7 @@ See here: http://vansande.org/2015/03/20/npm-link/
105108
106109## Release History
107110
111+ * 0.3.0 proxyIntegration: allow for custom status codes from route (thanks to [ @mintuz ] ( https://github.com/mintuz ) )
108112* 0.2.2 proxyIntegration: set correct header values now for CORS
109113* 0.2.1 proxyIntegration: CORS in Preflight, status code 400 for invalid body, set more CORS headers as default
110114* 0.2.0 Attention: breaking changes for configuration; add SNS event process
0 commit comments