[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 ...
随机推荐
- android studio 开发android app 真机调试
大家都知道开发android app 的时候可以有2种调试方式, 一种是Android Virtual Device(虚拟模拟器) ,另一种就是真机调试. 这里要说的是真机调试的一些安装步骤: 1. ...
- vsftp虚拟用户登录配置详解
一.安装:1.安装Vsftpd服务:# yum install vsftpd 2.安装DB4部件包:这里要特别安装一个db4的包,用来支持文件数据库.# yum install db4-utils 二 ...
- python - 面向对象(一)
python是一门面向对象的编程语言,python中的一切均是对象. 有对象就提到类,对象和类就像是儿子和老子的关系,是不可分的一对. 什么是类 类就是具有一些共同特性的事物的统称.好比人类, ...
- Javascript进阶篇——总结--DOM案例+选项卡效果
断断续续的把慕课的JavaScript基础和进阶看完了,期间不怎么应用有的都忘记了,接下来多开始写些效果,进行实际应用. 制作一个表格,显示班级的学生信息. 1. 鼠标移到不同行上时背景色改为色值为 ...
- 学习unity的第一个小游戏(Roll the ball)的笔记
1.摄像机的跟随运动,逻辑就是保持摄像机跟主角的距离不变(Undate()函数). offset=trandform.position-player.position. Undate() { tran ...
- bootstrap小结
bootstrap总结 bootstrap总结 base css 我分为了几大类 1,列表 .unstyled(无样式列表),.dl-horizontal(dl列表水平排列) 2,代码 code(行级 ...
- JS常用的方法
1.时间戳转换 //时间戳(有Date和无Date的都可)转换为日期 “2016年5月30日 10:29:30 2016-05-20 09:11” function TimeConversion(ti ...
- 关于JS中的this关键字
在学习js时,应该先了解下this关键字,关于js中的this关键字和其他的面向对象语言中的this是不同的,比如在java中,this指的的是当前对象,而在js中,w3c是这样规定的: 关键字 th ...
- php 远程下载图片到本地
大家好,从今天开始,小弟开始写写博客,把自己在工作中碰到的问题的解决方法纪录下来,方便以后查找,也给予别人方便,小弟不才,第一次写博客,有什么不足之处请指出,谢谢! 今天纪录的是怎么通过PHP远程把图 ...
- [php] PHP创建指定目录和文件
前几天看到有人问PHP环境下如何创建文件到指定目录下,正好自己最近在学习,经过一翻测试,终于出结果了,贴出来与大家分享. 目录结构: 代码所在的文件wwwroot/mydir/test/test.ph ...