https://github.com/doneee/validate-request-parameters
The purpose of this module is to enable configurable query parameter validation from HTTP request events, such as API Gateway Events or Express Routes.
https://github.com/doneee/validate-request-parameters
api-gateway express-js lambda node query-string-parameters query-validation type-coercion
Last synced: 8 months ago
JSON representation
The purpose of this module is to enable configurable query parameter validation from HTTP request events, such as API Gateway Events or Express Routes.
- Host: GitHub
- URL: https://github.com/doneee/validate-request-parameters
- Owner: doneee
- Created: 2022-02-17T22:25:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-25T20:40:45.000Z (almost 4 years ago)
- Last Synced: 2025-04-18T19:52:51.440Z (10 months ago)
- Topics: api-gateway, express-js, lambda, node, query-string-parameters, query-validation, type-coercion
- Language: TypeScript
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# validate-request-parameters
The purpose of this module is to enable configurable query parameter validation from HTTP request
events, such as API Gateway Events or Express Routes.
## Key Features
* Type Coercion
* Type Enforcement
* Default Values
* Defined Value Options
* Regular Expression Matching
* Apply Transforms to Values
* Numeric Value Ranges
* String Length Ranges
## Working
* AWS APIGatewayEvent Handling (Lambda)
* Query String Parameter Validation
# Not Working, yet
* Multi Value Query String Parameters
* Request Body JSON Validation
* Express.js Support
## Lambda API Gateway Example
```typescript
// https://.../query?searchTerm=code&limit=10&offset=10&order=asc&orderBy=name
import {
validateAPIGatewayEvent,
QueryStringValueTypes,
} from '@doneee/validate-request-parameters';
import { toUpperCase, toLowerCase } from '@doneee/composable-transform-functions';
const config = {
queryStringParameters: {
offset: {
type: QueryStringValueTypes.Integer,
min: 0,
defaultValue: 0,
},
limit: {
type: QueryStringValueTypes.Integer,
min: 1,
max: 100,
defaultValue: 10,
},
searchTerm: {
type: QueryStringValueTypes.String,
regex: /[a-z0-9]+/gi,
min: 4,
max: 75,
},
order: {
type: QueryStringValueTypes.String,
options: ['ASC', 'DESC'],
defaultValue: 'ASC',
transforms: [ toUpperCase ],
},
orderBy: {
type: QueryStringValueTypes.String,
transforms: [ toLowerCase ],
options: [
'name',
'date',
],
defaultValue: 'name',
},
},
};
exports.handler = (event) => {
const [ params, paramErrors ] = validateAPIGatewayEvent(event, config);
// params = {
// queryStringParameters: {
// offset: 10,
// limit: 10,
// searchTerm: 'code',
// order: 'ASC',
// orderBy: 'name',
// },
// };
// Use params without needing to do additional type checks or validation
}
```