https://github.com/nukeop/express-enum-param
Middleware for ensuring that a request parameter can only assume certain values
https://github.com/nukeop/express-enum-param
Last synced: about 1 year ago
JSON representation
Middleware for ensuring that a request parameter can only assume certain values
- Host: GitHub
- URL: https://github.com/nukeop/express-enum-param
- Owner: nukeop
- License: agpl-3.0
- Created: 2018-12-13T09:05:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-13T09:15:21.000Z (over 7 years ago)
- Last Synced: 2025-06-06T06:36:21.574Z (about 1 year ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-enum-param
Middleware for ensuring that a request parameter can only assume certain values
## Installation
```shell
$ npm install --save express-enum-param
```
Requires `body-parser`.
## Usage
```javascript
import enumParam from 'express-enum-param';
let allowedAnimals = ['crocodile', 'heron', 'turtle'];
router.get('/',
enumParam('animal', allowedAnimals),
(req, res) => {
res.status(200).send();
});
```
The above code will return a 400 HTTP status code and a message informing the client that this parameter can only have values from a certain list if `animal` is anything else than `crocodile`, `heron`, or `turtle`.
## About
### License
Copyright © 2018, [nukeop](https://github.com/nukeop).
Released under the [Affero GPL 3.0 License](LICENSE).