@middy/http-router
Advanced tools
Comparing version 4.0.0 to 4.0.1
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12168
46
+ Added@middy/util@4.0.1(transitive)
- Removed@middy/util@4.0.0(transitive)
Updated@middy/util@4.0.1