[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 ...
随机推荐
- [RxJS] Logging a Stream with do()
To help understand your stream, you’ll almost always want to log out some the intermediate values to ...
- [Javascript] Redirect the browser using JavaScript
Three methods to preform redirection in browser: widnow.location.href window.location.assign window. ...
- WebSphere之wasprofile.sh使用
概要文件(profile) 6.0版本以后才有profile,目的是将用户数据和was本身的文件分开,这样可以定义多个profile,每个profile相当于一个用户,相当于提供了多用户的支持. pr ...
- jQuery.extend 和 jQuery.fn.extend
1.jQuery.extend 我们先把jQuery看成了一个类,这样好理解一些.jQuery.extend(),是扩展的jQuery这个类. 假设我们把jQuery这个类看成是人类,能吃饭能喝水能跑 ...
- html5图片标签与属性
标记: 标 记 说 明 <lmg> 图像 <Map> 图像映射 <Area> 图像映射中定义区域 <lmg>标记属性: 属 性 说 明 Src ...
- Masters of Doom
http://blog.codinghorror.com/you-dont-need-millions-of-dollars/ "In the information age, the ba ...
- Mac_配置adb环境变量
1.打开终端Terminal. 2.进入HOME目录:命令行输入 echo(这之间有一个空格) $HOME 3.创建.bash_profile文件:命令行输入 touch(这之间有一个空格).bash ...
- oracle登录错误(ORA-01033:ORACLE initialization or shutdown in progress
在网上查找出现这种错误的原因一般是因为删除数据库 安装文件下的某个文件造 成的, 但是在我们的服务器上是因为 机子重启(意外断电)了一下就造 成这样的错误,不过解决办法是一样的,下面贴上解决方案 解决 ...
- silverlight 打印
加引用: using System.Windows.Printing; xaml文件里: //定义图片和文本打印变量 PrintDocument printImage; public BeginCo ...
- 关于Jquery.validate.js中动态删除验证remove方法的Bug
利用Jquery.validate.js 来做动态验证的时候,需要特定的情况下,删除添加opAmount的必须入力的Check $("#form").validate({ rule ...