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. [RxJS] Adding Conditional Logic with Filter

    Often you only want values to proceed through your stream if they meet certain criteria, just as if ...

  2. jquery之null的数组

    去掉null的数组 function ClearNullArr(arr) {    for (var i = 0;  i < arr.length; i++) {         if(arr[ ...

  3. My way to Python - Day04 - 模块

    re模块 什么是正则表达式 正则表达式,英文叫做Regular Expression.简单说,正则表达式就是一组规则,用于实现字符串的查找,匹配,以实现关于字符串的相关操作,比如替换,删除等. 正则表 ...

  4. SVN CornerStone的使用

    http://www.henishuo.com/mac-cornerstone-svn-use/

  5. iOS9TableView分割线默认不显示,只有滑动的时候才显示 解决办法

    只有iOS9和iPhone6 plus模拟器上TableView分割线不会显示,后来终于找到了原因: 由于iPhone6 plus的分辨率较高,开发的时候同常都使用command + 3 或者 com ...

  6. C#中Byte转换相关的函数

    1.将一个对象转换为byte对象 public static byte GetByte(object o) { ; if (o != null) { byte tmp; if (byte.TryPar ...

  7. hdu 1232畅通工程

    Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通 ...

  8. ci 的控制器文件夹下开加子文件夹

    在一个比较大的项目中,希望controllers下再细分子文件夹.例如:controllers/pj,controllers/xxk等. 做法是: 1.在controllers下添加相关的子文件夹,例 ...

  9. Python一路走来 面向对象1

    面向对象: 类,对象 函数放在类里,叫方法 封装 #如何调用 1. 创建对象, 类名() obj= Foo() 2. 通过对象去执行方法 obj.mail("leon@me.com" ...

  10. Rescue--hdu1242

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...