Skip to content

Routing middleware for Middy that provides path parameters in the event

License

Notifications You must be signed in to change notification settings

iress/iress-middy-http-path-router

Repository files navigation

iress-middy-http-path-router

@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.

Install

npm install @iress/middy-http-path-router
# or
yarn add @iress/middy-http-path-router

Usage

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));

More about routing

The responsibility for recognising routes and parameters is handled by route-recognizer.

Contributing

  1. Fork the repo
  2. Make the changes
  3. Run the tests
  4. Commit and push your changes
  5. Send a pull request

About

Routing middleware for Middy that provides path parameters in the event

Resources

License

Stars

Watchers

Forks

Packages

No packages published