8000 Added more doc to the response function · aceew/lambda-proxy-router@df4fe47 · GitHub
[go: up one dir, main page]

Skip to content

Commit df4fe47

Browse files
committed
Added more doc to the response function
1 parent 5149137 commit df4fe47

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Coverage Status](https://coveralls.io/repos/github/aceew/lambda-proxy-router/badge.svg?branch=master)](https://coveralls.io/github/aceew/lambda-proxy-router?branch=master)
55
[![Build Status](https://travis-ci.org/aceew/lambda-proxy-router.svg?branch=master)](https://travis-ci.org/aceew/lambda-proxy-router)
66

7-
The purpose of this package is to easily organize the mapping between your code and your API request within Lambda functions that have more than one single purpose. This takes away the need for the configuration of mapping templates and handles the standard event Amazon send through with Lambda functions with proxy configuration. The desired effect of the package is to make it easier to build microservices that have multiple API Gateway endpoints.
7+
The purpose of this package is to easily organize the mapping between your code and your API request within Lambda functions that have more than one purpose. This takes away the need for the configuration of mapping templates and handles the standard event object that Amazon sends through with Lambda functions with proxy configuration. The desired effect of the package is to make it easier to build microservices that have multiple API Gateway endpoints.
88

99
## Contents
1010
- [Usage](#usage)
@@ -110,9 +110,27 @@ Here's all the keys that are currently available in the request object:
110110

111111

112112
## Response
113-
The response parameter is used to send a response back to API gateway. This method requires a parameter object to specify the body, headers and http status code. If none of these are specified, default values of empty headers, statusCode 200, and a stringified value of whatever was sent in the parameter.
113+
The response parameter is used to send a response back to API gateway. This method requires a parameter object to specify the body, headers and http status code.
114114

115-
So `response("hello world")` would work out as:
115+
| Key | Type | Value | Default
116+
|---|---|---
117+
| params | Object | Parameters object | {} |
118+
| params.statusCode | integer | The HTTP status code | 200
119+
| params.headers | Object | Any headers to be returned in the response. | {}
120+
| params.body | mixed | Your response body, whatever is specified will be `JSON.stringify`'d. If body is not set the body will be defined as the params object. | `JSON.stringify(params)`
121+
122+
Here is the recommended way to call the response method.
123+
```
124+
response({
125+
statusCode: 200,
126+
headers: { "x-your-header": "header value" },
127+
body: { "response-object-key": "data" },
128+
});
129+
```
130+
131+
If any of the correct parameters are not specified, default values of empty headers, statusCode 200, and a stringified value of whatever was sent in the parameter for the body are used to make the response valid.
132+
133+
So `response('hello world')` would work out as:
116134
```
117135
{
118136
statusCode: 200,

0 commit comments

Comments
 (0)
0