An open API service indexing awesome lists of open source software.

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

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/).

[![Request body validation in Node](images/node-request-body-validation.png)](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.