Socket
Socket
Sign inDemoInstall

@middy/http-router

Package Overview
Dependencies
Maintainers
3
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/http-router - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

8

package.json
{
"name": "@middy/http-router",
"version": "4.0.0",
"version": "4.0.1",
"description": "HTTP event router for the middy framework",

@@ -65,9 +65,9 @@ "type": "module",

"dependencies": {
"@middy/util": "4.0.0"
"@middy/util": "4.0.1"
},
"devDependencies": {
"@middy/core": "4.0.0",
"@middy/core": "4.0.1",
"@types/aws-lambda": "^8.10.97"
},
"gitHead": "582286144bcd79968a8c7c2f8867a23c80079a47"
"gitHead": "c5ece2bfbb0d607dcdea5685bf194a6cc19acc8d"
}

@@ -39,76 +39,2 @@ <div align="center">

This handler can route to requests to one of a nested hander based on `method` and `path` of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer.
## Install
To install this middleware you can use NPM:
```bash
npm install --save @middy/http-router
```
## Options
- `routes` (array[{method, path, handler}]) (required): Array of route objects.
- `method` (string) (required): One of `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS` and `ANY` that will match to any method passed in
- `path` (string) (required): AWS formatted path starting with `/`. Variable: `/{id}/`, Wildcard: `/{proxy+}`
- `handler` (function) (required): Any `handler(event, context)` function
NOTES:
- Errors should be handled as part of the router middleware stack **or** the lambdaHandler middleware stack. Handled errors in the later will trigger the `after` middleware stack of the former.
- Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack.
## Sample usage
```javascript
import middy from '@middy/core'
import validatorMiddleware from '@middy/validator'
const getHandler = middy()
.use(validatorMiddleware({eventSchema: {...} }))
.handler((event, context) => {
return {
statusCode: 200,
body: '{...}'
}
})
const postHandler = middy()
.use(validatorMiddleware({eventSchema: {...} }))
.handler((event, context) => {
return {
statusCode: 200,
body: '{...}'
}
})
handler = middy()
.use(httpHeaderNormalizer())
.handler(httpRouterHandler([
{
method: 'GET',
path: '/user/{id}',
handler: getHandler
},
{
method: 'POST',
path: '/user',
handler: postHandler
}
]))
module.exports = { handler }
```
## Middy documentation and examples
For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
## Contributing
Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
## License

@@ -115,0 +41,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc