Skip to content

Commit

Permalink
Merge pull request #10 from geoffdutton/issue-9
Browse files Browse the repository at this point in the history
adds .getLambdaEvent()
  • Loading branch information
geoffdutton committed Apr 30, 2019
2 parents 228ae44 + e719dd6 commit affc4b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ module.exports.lambdaHandler = function(event, context, callback) {
// Check the type
req.is('html') // false

// Get an AWS API Gateay requestContext property
// Get an AWS API Gateway requestContext property
req.context('requestId') // '08e3e2d0-daca-11e6-8d84-394b4374a71a'

// Get the unmodified Lambda Proxy event
req.getLambdaEvent()
}
```

Expand Down
9 changes: 9 additions & 0 deletions src/events/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ class Request {
return this.headers[field.toLowerCase()]
}

/**
* Returns the unmodified Lambda Proxy Event
*
* @returns {object} - Lambda event
*/
getLambdaEvent () {
return this.rawLambdaEvent
}

/**
* Returns true if the incoming request’s “Content-Type” HTTP header field matches the MIME type
* specified by the type parameter. Returns false otherwise.
Expand Down
6 changes: 6 additions & 0 deletions test/events/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,11 @@ describe('events', () => {
expect(req.context('requestId')).to.eq('08e3e2d0-daca-11e6-8d84-394b4374a71a')
})
})

describe('#getLambdaEvent', () => {
it('should return the raw lambda event', () => {
expect(new Request(lambdaEvent).getLambdaEvent()).to.eq(lambdaEvent)
})
})
})
})

0 comments on commit affc4b2

Please sign in to comment.