当前位置: 首页 > 软件库 > Web应用开发 > >

bodymen

授权协议 View license
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 薛望
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

bodymen

Bodymen works similarly to Querymen and has almost the same functionality, expect it formats, validates and parses request body instead of querystrings. Refer to Querymen's readme to find out more.

Prerequisites

You must use a request body parser like express body-parser and set it up before using bodymen:

import express from 'express'
import bodyParser from 'body-parser'

const app = express()

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

Install

npm install --save bodymen

Usage

Bodymen allows you to define a schema to control the fields sent through the request body.

import bodymen, { errorHandler } from "bodymen"

app.post('/posts', bodymen.middleware({
  title: {
    type: String,
    required: true,
    trim: true,
    minlength: 3
  },
  content: {
    type: String,
    required: true,
    minlength: 32
  },
  tags: [String]
}), (req, res) => {
  console.log(req.bodymen.body) // will contain the parsed body
})

app.use(errorHandler()) // will send standard error messages, similar to Querymen

License

MIT © Diego Haz

相关阅读

相关文章

相关问答

相关文档