1.0.0 • Published 4 years ago

@kdcsoftware/api-gw-req v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

API Gateway Request Parser

ver build codecov size license

Maintainability Code Issues Technical Debt

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 NameTypeDescription
pathstringPath of the query
queryobjectQuery string object
headersobjectHTTP headers
ipstringIP Address of the client
userAgentstringUser Agent of the http client
pathParamsobjectPath parameters if defined in API Gateway
bodyobjectBody parsed as json or as urlencoded form data.
authorizerobjectAuthorizer object

See also

@kdcsoftware/api-gw-resp

1.0.0

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago