https://github.com/jangbl/node-request-body-validation
demonstrates how to validate the request body of requests in Node
https://github.com/jangbl/node-request-body-validation
data-transfer-object dto express-request-validation javascript node node-request-body request-body request-validate request-validation request-validator
Last synced: 6 months ago
JSON representation
demonstrates how to validate the request body of requests in Node
- Host: GitHub
- URL: https://github.com/jangbl/node-request-body-validation
- Owner: jangbl
- Created: 2020-06-18T17:52:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-13T11:04:04.000Z (almost 3 years ago)
- Last Synced: 2025-04-19T00:41:08.933Z (12 months ago)
- Topics: data-transfer-object, dto, express-request-validation, javascript, node, node-request-body, request-body, request-validate, request-validation, request-validator
- Language: JavaScript
- Size: 972 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node request body validation
This repository contains sample code on how to perform request body validation with the Node.js [express](https://expressjs.com/) framework and [yup](https://github.com/jquense/yup)
Please help this repo with a ⭐️ if you find it useful! 😁
This repository is part of the [Request body validation in Node](https://www.youtube.com/playlist?list=PL1Nml43UBm6dM110xcNUvdYgbQ3cnIBJm) tutorial series provided by [productioncoder.com](https://productioncoder.com/).
[](https://www.youtube.com/playlist?list=PL1Nml43UBm6dM110xcNUvdYgbQ3cnIBJm)
For updates, please reach out to [@_jgoebel](https://twitter.com/_jgoebel) on Twitter.
# How to run this application
## Running the project
Make sure to install the dependencies with `npm`
```
npm install
```
You can then run the project by executing
```
npm run dev
```
## API
### POST /dev
Expected payload
```
{
"email": "john@example.com",
"firstName": "John",
"dob": "12-31-1950",
"countryCode": "US"
}
```
The server will return a `400` bad request error if the request body does not conform to the expected DTO (data transfer object).
Please check out the `./dto` directory to learn more about the expected request body.