Skip to content

Commit

Permalink
Merge pull request #147 from stawecki/issue-110
Browse files Browse the repository at this point in the history
Add default export to match TypeScript definition #110
  • Loading branch information
jeremydaly authored Apr 27, 2020
2 parents 11c6ddd + 203959a commit 0f3af15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down 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.

```javascript
// import Lambda API and TypeScript declarations
import API from 'lambda-api'
**TypeScript Example**
```typescript
// 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 0f3af15

Please sign in to comment.