Skip to content

Commit 0a8940a

Browse files
author
Mateusz Stawecki
committed
Add default export to match TypeScript definition #110
1 parent 11c6ddd commit 0a8940a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,26 @@ If you are using persistent connections in your function routes (such as AWS RDS
13541354
## TypeScript Support
13551355
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.
13561356

1357+
** TypeScript Example **
13571358
```javascript
1358-
// import Lambda API and TypeScript declarations
1359-
import API from 'lambda-api'
1359+
// import AWS Lambda types
1360+
import { APIGatewayEvent, Context } from 'aws-lambda';
1361+
// import Lambda API default function
1362+
import createAPI from 'lambda-api'
1363+
1364+
// instantiate framework
1365+
const api = createAPI();
1366+
1367+
// Define a route
1368+
api.get('/status', async (req,res) => {
1369+
return { status: 'ok' }
1370+
})
1371+
1372+
// Declare your Lambda handler
1373+
exports.run = async (event: APIGatewayEvent, context: Context) => {
1374+
// Run the request
1375+
return await api.run(event, context)
1376+
}
13601377
```
13611378

13621379
## Contributions

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,5 @@ class API {
504504

505505
// Export the API class as a new instance
506506
module.exports = opts => new API(opts)
507+
// Add createAPI as default export (to match index.d.ts)
508+
module.exports.default = module.exports

0 commit comments

Comments
 (0)