From 0a8940a64b8d5243b5948d01718f73f7011cd09a Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Tue, 10 Mar 2020 19:16:59 +0000 Subject: [PATCH] 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