Skip to content

Commit 0f3af15

Browse files
authored
Merge pull request #147 from stawecki/issue-110
Add default export to match TypeScript definition #110
2 parents 11c6ddd + 203959a commit 0f3af15

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ api.get('/users', (req,res) => {
262262
})
263263
```
264264

265-
### Async/Await
265+
### Async/Await
266266

267267
If you prefer to use `async/await`, you can easily apply this to your route functions.
268268

@@ -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-
```javascript
1358-
// import Lambda API and TypeScript declarations
1359-
import API from 'lambda-api'
1357+
**TypeScript Example**
1358+
```typescript
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)