Skip to content

Commit

Permalink
Add default export to match TypeScript definition #110
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Stawecki committed Mar 10, 2020
1 parent 11c6ddd commit 0a8940a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0a8940a

Please sign in to comment.