From 0a8940a64b8d5243b5948d01718f73f7011cd09a Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Tue, 10 Mar 2020 19:16:59 +0000 Subject: [PATCH 1/2] Add default export to match TypeScript definition #110 --- README.md | 21 +++++++++++++++++++-- index.js | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index deda86f..b46a4b0 100644 --- a/README.md +++ b/README.md @@ -1354,9 +1354,26 @@ If you are using persistent connections in your function routes (such as AWS RDS ## TypeScript Support An `index.d.ts` declaration file has been included for use with your TypeScript projects (thanks @hassankhan). Please feel free to make suggestions and contributions to keep this up-to-date with future releases. +** TypeScript Example ** ```javascript -// import Lambda API and TypeScript declarations -import API from 'lambda-api' +// import AWS Lambda types +import { APIGatewayEvent, Context } from 'aws-lambda'; +// import Lambda API default function +import createAPI from 'lambda-api' + +// instantiate framework +const api = createAPI(); + +// Define a route +api.get('/status', async (req,res) => { + return { status: 'ok' } +}) + +// Declare your Lambda handler +exports.run = async (event: APIGatewayEvent, context: Context) => { + // Run the request + return await api.run(event, context) +} ``` ## Contributions diff --git a/index.js b/index.js index cae80a3..f24bdb0 100644 --- a/index.js +++ b/index.js @@ -504,3 +504,5 @@ class API { // Export the API class as a new instance module.exports = opts => new API(opts) +// Add createAPI as default export (to match index.d.ts) +module.exports.default = module.exports From 203959ae395013f907371d98511e70423ed00540 Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Wed, 11 Mar 2020 13:28:12 +0000 Subject: [PATCH 2/2] Updated README formatting --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b46a4b0..d8ece57 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ api.get('/users', (req,res) => { }) ``` -### Async/Await +### Async/Await If you prefer to use `async/await`, you can easily apply this to your route functions. @@ -1354,8 +1354,8 @@ If you are using persistent connections in your function routes (such as AWS RDS ## TypeScript Support An `index.d.ts` declaration file has been included for use with your TypeScript projects (thanks @hassankhan). Please feel free to make suggestions and contributions to keep this up-to-date with future releases. -** TypeScript Example ** -```javascript +**TypeScript Example** +```typescript // import AWS Lambda types import { APIGatewayEvent, Context } from 'aws-lambda'; // import Lambda API default function