@middy/http-event-normalizer 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -55
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -36,61 +36,6 @@
|
|
|
36
36
|
<p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-event-normalizer">https://middy.js.org/docs/middlewares/http-event-normalizer</a></p>
|
|
37
37
|
</div>
|
|
38
38
|
|
|
39
|
-
If you need to access the query string or path parameters in an API Gateway event you
|
|
40
|
-
can do so by reading the attributes in `event.queryStringParameters`, `event.multiValueQueryStringParameters` and
|
|
41
|
-
`event.pathParameters`, for example: `event.pathParameters.userId`. Unfortunately
|
|
42
|
-
if there are no parameters for these parameter holders, the relevant key `queryStringParameters`, `multiValueQueryStringParameters` or `pathParameters` won't be available in the object, causing an expression like `event.pathParameters.userId`
|
|
43
|
-
to fail with the error: `TypeError: Cannot read property 'userId' of undefined`.
|
|
44
|
-
|
|
45
|
-
A simple solution would be to add an `if` statement to verify if the `pathParameters` (or `queryStringParameters`/`multiValueQueryStringParameters`)
|
|
46
|
-
exists before accessing one of its parameters, but this approach is very verbose and error prone.
|
|
47
|
-
|
|
48
|
-
This middleware normalizes the API Gateway event, making sure that an object for
|
|
49
|
-
`queryStringParameters`, `multiValueQueryStringParameters` and `pathParameters` is always available (resulting in empty objects
|
|
50
|
-
when no parameter is available), this way you don't have to worry about adding extra `if`
|
|
51
|
-
statements before trying to read a property and calling `event.pathParameters.userId` will
|
|
52
|
-
result in `undefined` when no path parameter is available, but not return an error.
|
|
53
|
-
|
|
54
|
-
> Important note : API Gateway HTTP API format 2.0 doesn't have `multiValueQueryStringParameters` fields. Duplicate query strings are combined with commas and included in the `queryStringParameters` field.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## Install
|
|
58
|
-
|
|
59
|
-
To install this middleware you can use NPM:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
npm install --save @middy/http-event-normalizer
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Options
|
|
67
|
-
None
|
|
68
|
-
|
|
69
|
-
## Sample usage
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
import middy from '@middy/core'
|
|
73
|
-
import httpEventNormalizer from '@middy/http-event-normalizer'
|
|
74
|
-
|
|
75
|
-
const handler = middy((event, context) => {
|
|
76
|
-
console.log(`Hello user ${event.pathParameters.userId}`)
|
|
77
|
-
return {}
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
handler.use(httpEventNormalizer())
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## Middy documentation and examples
|
|
85
|
-
|
|
86
|
-
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).
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Contributing
|
|
90
|
-
|
|
91
|
-
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).
|
|
92
|
-
|
|
93
|
-
|
|
94
39
|
## License
|
|
95
40
|
|
|
96
41
|
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-event-normalizer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Http event normalizer middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"url": "https://github.com/middyjs/middy/issues"
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "c5ece2bfbb0d607dcdea5685bf194a6cc19acc8d",
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@middy/core": "4.0.
|
|
66
|
+
"@middy/core": "4.0.1",
|
|
67
67
|
"@types/aws-lambda": "^8.10.101"
|
|
68
68
|
}
|
|
69
69
|
}
|