@safen/express
v0.1.1
Published
Express Validator Middleware using Safen.
Downloads
8
Maintainers
Readme
Install
npm install @safen/express --save
Usage
import * as safen from "@safen/express"
// or
const safen = require("@safen/express")
Basic Usage
const safen = require("@safen/express")
const express = require("express")
const app = express()
// body parser required
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.get("/users", safen.query(`{
q?: string
}`), (req, res) => {
res.send("show users!")
})
app.post("/users", safen.body(`{
username: email,
password: length_between(8,20)
}`), (req, res) => {
res.send("store users!")
})
app.use(safen.errorHandler())
app.listen()
query
method usereq.query
.body
method usereq.body
.
and, You can use params
method also.
params
method usereq.query
when HTTP method isGET
, otherwise usereq.params
.
License
MIT