[Hapi.js] Request Validation with Joi
hapi supports request validation out of the box using the joi module. Request path parameters, payloads, and querystring parameters can be validated with joi's simple,
'use strict'
const Hapi = require('hapi')
const Joi = require('joi')
const server = new Hapi.Server()
server.connection({ port: 8000 }) server.route({
method: ['POST','PUT'],
path: '/user/{id?}',
config: {
validate: {
params: Joi.object().keys({
id: Joi.number()
}),
payload: Joi.object().keys({
id: Joi.number()
email: Joi.string()
}).unknown(),
query: Joi.object().keys({
id: Joi.number()
})
},
handler: function(request, reply) {
reply({
params: request.params,
query: request.query
payload: request.payload
})
}
}
}) server.start(() => console.log(`Started at: ${server.info.uri}`))
[Hapi.js] Request Validation with Joi的更多相关文章
- jquery.form.js+jquery.validation.js实现表单校验和提交
一.jquery引用 主要用到3个js: jquery.js jquery.form.js jquery.validation.js 另外,为了校验结果提示本地化,还需要引入jquery.vali ...
- [Hapi.js] Extending the request with lifecycle events
Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...
- [Hapi.js] POST and PUT request payloads
hapi makes handling POST and PUT payloads easy by buffering and parsing them automatically without r ...
- [Hapi.js] View engines
View engines, or template engines, allow you to maintain a clean separation between your presentatio ...
- [Hapi.js] Up and running
hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...
- [Hapi.js] Managing State with Cookies
hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...
- [Hapi.js] Friendly error pages with extension events
hapi automatically responds with JSON for any error passed to a route's reply()method. But what if y ...
- [Hapi.js] Replying to Requests
hapi's reply interface is one of it's most powerful features. It's smart enough to detect and serial ...
- [Hapi.js] Route parameters
Routing is a fundamental aspect of any framework. In this lesson, you'll learn how to use path param ...
随机推荐
- c++11 线程:让你的多线程任务更轻松
介绍 本文旨在帮助有经验的Win32程序员来了解c++ 11线程库及同步对象 和 Win32线程及同步对象之间的区别和相似之处. 在Win32中,所有的同步对象句柄(HANDLE)是全局句柄.它们 ...
- Android-------------获取手机IP地址
##帮助类PhoneNetStateUtil package com.funs.PhoneIPAddress.utils; /** * 手机联网状态工具类 需要的权限 WIFI时:</ ...
- mysql忘记密码的处理方式(整理非原创)
方案1.通过跳过授权的方式 1.修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld]的中加上:skip-grant-tables . 2.重新启动mysqld # ubun ...
- KMP算法———模板
做出KMP字符串匹配算法心情也是好好哒,萌萌哒. 感谢黄学长,感谢栋栋! #include<cstdio>#include<string>#include<iostrea ...
- C#界面设计疑问2:panel摆放问题
1.问题1是这样的,网友意思让使用一个按键对应显示一个panel 即,http://zhidao.baidu.com/question/1924974374730559427.html 2.那么我在设 ...
- No2_5.类的高级特性_Java学习笔记_抽象类和成员内部类
一.抽象类1.所谓抽象类,只声明方法的存在而不去实现它的类:2.抽象类不能被实例化,即不能实现其对象:3.abstract class 类名{ 类体 }4.包含一个或多个抽象方法的类必须声明成抽象类: ...
- ssh-agent自启动加key脚本
公司使用到阿里云. 需要使用 ssh-agent forward 来跳转.为了方便自己就写了这个脚本 1 #!/bin/sh 2 # auto start ssh-agent and add key ...
- CSS实现背景透明/半透明效果的方法
全透明代码:{background:transparent} 半透明代码:{filter:alpha(opacity=80);-moz-opacity:0.8;width:auto !importan ...
- Android CursorAdapter
CursorAdapter 继承于BaseAdapter是个虚类,它为cursor和ListView提供了连接的桥梁. public abstract class Cur ...
- haproxy简单负载均衡搭建
最近对负载均衡进行搭建具体方法如下: haproxy 修改部分(haproxy-cfg.cfg) global daemon maxconn 4500 defaults mode http timeo ...