@iress/middy-http-path-router
is middleware for Middy
that routes API Gateway events to handlers based on static and dynamic paths.
For dynamic paths it will include the parameters within the event.pathParameters
.
npm install @iress/middy-http-path-router
# or
yarn add @iress/middy-http-path-router
import { httpPathRouteHandler, Route } from '@iress/middy-http-path-router';
const routes: Route[] = [{
method: 'GET',
path: '/api/hello/:name',
handler: (event: APIGatewayProxyEvent): APIGatewayProxyResult => {
return {
statusCode: 200,
body: event.pathParameters?.name ?? 'anonymous'
}
}
}];
const handler = middy()
.handler(httpPathRouteHandler(routes));
The responsibility for recognising routes and parameters is handled by route-recognizer.
- Fork the repo
- Make the changes
- Run the tests
- Commit and push your changes
- Send a pull request