When you use reply method:

let resp = reply('hello world')

It actually return an response object.

By using response object, you can modiy the response's status code, header, cookie, type and so on...

server.route({
method: 'GET',
path: '/',
handler: function(request, reply) {
let resp = reply('hello world')
resp.code(418) // set status code to 418
resp.type('text/plain') // set type to text/plain
resp.header('hello', 'world') // set header to hello: world
resp.state('hello', 'world') // set cookie to hello=world
}

response object is chainable:

server.route({
method: 'GET',
path: '/',
handler: function(req, reply){
reply('hello world')
.code(418)
.type('text/plain')
.header('hello', 'world')
-state('hello', 'world')
}
})

[Hapi.js] Using the response object的更多相关文章

  1. 【前端】js中new和Object.create()的区别

    js中new和Object.create()的区别 var Parent = function (id) { this.id = id this.classname = 'Parent' } Pare ...

  2. js动态参数作为Object的属性取值

    js动态参数作为Object的属性取值var myObj = {"a":1,"b":2};var a = 'a';myObj[a] 就可以获取到 属性a的值了

  3. JS中==、===和Object.is()的区别

    JS中==.===和Object.is()的区别 首先,先粗略了解一下这三个玩意儿: ==:等同,比较运算符,两边值类型不同的时候,先进行类型转换,再比较: ===:恒等,严格比较运算符,不做类型转换 ...

  4. js中关于new Object时传参的一些细节分析

    1, 参数是一个对象,核心js对象(native ECMAScript object)或宿主对象(host object),那么将直接返回该对象. 其生成的对象构造器仍然是所传参数对象的构造器.这样造 ...

  5. js arrow function return object

    js arrow function return object bug filterData: { type: Object, default: () => {}, required: true ...

  6. [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 ...

  7. [转]Build An Image Manager With NativeScript, Node.js, And The Minio Object Storage Cloud

    本文转自:https://www.thepolyglotdeveloper.com/2017/04/build-image-manager-nativescript-node-js-minio-obj ...

  8. [Hapi.js] Managing State with Cookies

    hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...

  9. [Hapi.js] Request Validation with Joi

    hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...

随机推荐

  1. 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)

    0.表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user ...

  2. js图片放大镜特效代码

    <script language="JavaScript"> <!-- var srcX = 1024; //原图长宽 var srcY = 768; var b ...

  3. android之保存偏好设置信息到shareSharedPreferences,轻量级的保存数据的方法

    android之保存偏好设置信息到shareSharedPreferences,轻量级的保存数据的方法   SharedPreferences保存数据到xml文件 有时候要保存activity的某些状 ...

  4. dwz笔记之tree权限扩展

    碰到的问题:tree选择子节点时,父级节点的值没有选择 解决方法如下(红色部分): 原代码: _checkParent:function(){ if($(this).parent().hasClass ...

  5. CSS3 中的按钮效果与进度条

    效果如图

  6. php 序列化储存和转化 json_encode() json_decode($q,true)

    序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性. 例如:当需要数据库只有一个 ...

  7. WordPress nginx环境下开启多站点

    在wp-config.php插入 define('WP_ALLOW_MULTISITE', true); 进入管理页面安装网络,子目录模式按提示再在wp-config.php插入 define('MU ...

  8. 列表:一个打了激素的数组 - 零基础入门学习Python010

    列表:一个打了激素的数组 让编程改变世界 Change the world by program 列表:一个打了激素的数组 有时候我们需要把一堆东西暂时存储起来,因为他们有某种直接或者间接的联系,我们 ...

  9. AFNetworiking与ASIHttpRequest对比

    在开发iOS应用过程中,如何高效的与服务端API进行数据交换,是一个常见问题.一般开发者都会选择一个第三方的网络组件作为服务,以提高开发效率和稳定性.这些组件把复杂的网络底层操作封装成友好的类和方法, ...

  10. HDU 5492(DP) Find a path

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5492 题目大意是有一个矩阵,从左上角走到右下角,每次能向右或者向下,把经过的数字记下来,找出一条路径是 ...