about 1 year ago
When I started working with lambda functions I struggled to find a simple solution to check if the correct values were present either in a JSON body or as a query parameter.
I stumbled upon a useful package on npm - node-input-validator - and this was a big step in the right direction. Here is a simple example:
This only checks that there is a value for uuid in the query parameter. A more complex situation could have completely custom validation of the value as well as a custom error message:
When making a mistake in calling your API, you would now get a specific error message:
Whilst it isn't perfect, it covered my use case pretty well and has saved me time multiple times.