0.0.2 • Published 6 years ago

dto-types v0.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

dto-types

GitHub licensenpm

DtoTypes is middleware for express based on PropTypes. PropTypes are an effective mechanism for keeping track of what a component should be receiving, so why not extend the idea to a DTOs (data transfer objects). I've found myself, instead writing custom validation for every api route I write. Hopefully this alleviates that by specifying the dto shapes only one time.

NPM

Installation

npm install --save dto-types

Use

import { DtoTypes, DtoValidator } from 'dto-types'; // ES6

const orderDtoType = {
  total: DtoTypes.number.isRequired,
  items: DtoTypes.arrayOf(DtoTypes.shape({
    name: DtoTypes.string.isRequired,
    price: DtoTypes.number.isRequired,
  }).isRequired,
}

app.post('/orders', DtoValidator(orderDtoType), (req, res) => { // do stuff })
0.0.2

6 years ago

0.0.1

7 years ago