@kdcsoftware/api-gw-req
v1.0.0
Published
Parse API Gateway request
Downloads
4
Readme
API Gateway Request Parser
This module will parse the event object (that came from API Gateway) in lambda and create a new object with all unnecessary fields stripped out.
Install
npm i @kdcsoftware/api-gw-req
Note: Breaking change from v0.1.x to 0.2.x: pathParams change to params.
Usage
const parser = require('@kdcsoftware/api-gw-req');
module.exports = (event) => {
const request = parser(event);
console.log(request);
};
Sample request
object:
{
"path": "/users/me",
"method": "GET",
"query": {},
"headers": {
"host": "localhost:8101",
"connection": "keep-alive",
"origin": "http://localhost:8100",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
"content-type": "application/json",
"accept": "*/*",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"referrer": "http://localhost:8100/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9,th;q=0.8"
},
"ip": "127.0.0.1",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
"params": { "proxy": "me" },
"body": {},
"authorizer": {}
}
Parsed Object
| Field Name | Type | Description | | ---------- | ------ | ----------------------------------------------- | | path | string | Path of the query | | query | object | Query string object | | headers | object | HTTP headers | | ip | string | IP Address of the client | | userAgent | string | User Agent of the http client | | pathParams | object | Path parameters if defined in API Gateway | | body | object | Body parsed as json or as urlencoded form data. | | authorizer | object | Authorizer object |